|
Home >Online Product Documentation >Table of Contents > Searching for Strings Searching for StringsThis section provides information about searching for strings. This section discusses the following topics: Finding Identical StringsIn a document, you can search for text that is an exact match with what you specify in your query. For example, consider the following query: This query finds all name elements that contain only the text Lu. It would return elements like these: The same query does not return elements like these: The XPath processor does not return the first name element because the comparison is between "Lu" and "Lu Chen". The query does not return the second name element because the XPath processor concatenates the two strings "Lu" and "Chen" before it makes the evaluation. Consequently, the comparison is between "Lu" and "LuChen". Note that the XPath processor does not insert a space between text nodes that it concatenates. Case SensitivitySearches are case sensitive. A search for "Lu" does not return "lu". Finding Strings That Contain Strings You SpecifyTo obtain elements that contain a particular string, call the contains() function. The format is The contains() function returns true if the first argument string contains the second argument string, and otherwise returns false. For example, the following query returns all books that have a title that contains the string "Trenton": When the first argument is a node list, the XPath processor tests only the string value of the node in the node list that is first in document order. Any subsequent nodes are ignored. Finding Substrings That Appear Before Strings You SpecifyTo obtain a substring that appears before a string you specify, call the substring-before() function. The format is The substring-before() function returns the substring of the first argument string that precedes the first occurrence of the second argument string in the first argument string. This function returns the empty string if the first argument string does not contain the second argument string. For example, the following call returns "1999": Finding Substrings That Appear After Strings You SpecifyTo obtain a substring that appears after a string you specify, call the substring-after() function. The format is The substring-after() function returns the substring of the first argument string that follows the first occurrence of the second argument string in the first argument string. This function returns the empty string if the first argument string does not contain the second argument string. For example, the following call returns "04/01": Finding Substrings by PositionTo obtain a substring that is in a particular position within its string, call the substring() function. The format is The substring() function returns the substring of the first argument, starting at the position specified in the second argument, with length specified in the third argument. For example, the following returns "234": If you do not specify the third argument, the substring() function returns the substring starting at the position specified in the second argument and continuing to the end of the string. For example, the following call returns "2345": More precisely, each character in the string is considered to have a numeric position. The position of the first character is 1. The position of the second character is 2, and so on. The returned substring contains those characters for which the position of the character is greater than or equal to the rounded second argument and, if the third argument is specified, less than the sum of the value of the second and third arguments. The comparisons and addition used for the preceding follow the standard IEEE 754 rules. The XPath processor rounds the second and third arguments as if by a call to the round() function. For example: |