Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这个问题听起来很基础;但是,我一直在尝试找到一些与之相关的资源。
假设有一系列字符或字符串:
let $abc := ('a', 'b', 'c', 'd', 'e', 'f') return (for $i in $abc return $i)
上面的查询会给我一个序列的各个元素。
但是,如果我只有一个字符串,如何检索它的每个元素?
e.g. let $abc = "abc"
如何从中获取“a” $abc,有没有$abc[0]这样的做法?
$abc
$abc[0]
你也可以使用
for $char in string-to-codepoints($abc)!codepoints-to-string(.) return ...
您不能在 XQuery 中将字符串作为数组访问,但可以使用substring:
substring
let $abc := "abcd" for $i in (1 to string-length($abc)) return substring($string, $i, 1)