RWUString provides several pattern matching methods based on simple lexical comparisons of the code units in the strings:
The contains() method returns true if a string contains a given pattern.
The index() method returns the index of the first occurrence of a pattern match, or RW_NPOS if the pattern is not found. For example, assuming pattern and text are RWUString objects:
int32_t location = text.index(pattern); if (location == RW_NPOS) { std::cout << "Pattern not found." << std::endl; } else { std::cout << "Pattern found at location: " << location << std::endl; }
The rindex() method returns the index of the last occurrence of a pattern match, or RW_NPOS if the pattern is not found.
The substring() method returns a substring representing the first occurrence of a match. The returned substring can be used as an lvalue to replace a pattern in a string. For example, this code replaces the first occurrence of pattern in text with RWUString replacement:
text.subString(pattern) = replacement;
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.