ISBN: 1491915103

2nd edition, , O'Reilly Media, Inc.

Chapter 18: Working with Strings

Please note that the book contains many inline examples and informal tables that are not provided here.

Table 18-2. Examples of contains, contains-token, starts-with, and ends-with
ExampleReturn value
contains("query", "ery") true
contains("query", "x") false
contains-token("xml query", "query") true
contains-token( ("xml", "query"), "query") true
starts-with("query", "que") true
starts-with("query", "u") false
ends-with("query", "y") true
ends-with("query ", "y") false
Table 18-3. Examples of the matches function
ExampleReturn value
matches("query", "q") true
matches("query", "qu") true
matches("query", "xyz") false
matches("query", "q.*") true
matches("query", "[a-z]{5}") true
Table 18-4. Examples of the substring functions
ExampleReturn value
substring("query", 2, 3) uer
substring("query", 2) uery
substring-before("query", "er") qu
substring-before("queryquery", "er") qu
substring-after("query", "er") y
substring-after("queryquery", "er") yquery
Table 18-5. Examples of the string-length function
ExampleReturn value
string-length("query") 5
string-length(" query ") 7
string-length(normalize-space(" query ")) 5
string-length("") 0
string-length(" ") 1
Table 18-7. Examples of the tokenize function
ExampleReturn value
tokenize("a b c", "\s") ("a", "b", "c")
tokenize("a b c", "\s+") ("a", "b", "c")
tokenize("a-b--c", "-") ("a", "b", "", "c")
tokenize("-a-b-", "-") ("", "a", "b", "")
tokenize("a/ b/ c", "[/\s]+") ("a", "b", "c")
tokenize("2015-12-25T12:15:00", "[\-T:]") ("2015", "12", "25", "12", "15", "00")
tokenize("Hello, there.", "\W+") ("Hello", "there")
Table 18-9. Examples of the upper-case and lower-case functions
ExampleReturn value
upper-case("query") QUERY
upper-case("Query") QUERY
lower-case("QUERY-123") query-123
lower-case("Query") query
Table 18-10. Examples of the replace function
ExampleReturn value
replace("query", "r", "as") queasy
replace("query", "qu", "quack") quackery
replace("query", "[ry]", "l") quell
replace("query", "[ry]+", "l") quel
replace("query", "z", "a") query
replace("query", "query", "") A zero-length string
Table 18-11. Examples of the normalize-space function
ExampleReturn value
normalize-space("query") query
normalize-space(" query ") query
normalize-space("xml query") xml query
normalize-space(" xml  query ") xml query
normalize-space(" ") A zero-length string
Datypic XQuery Services