String :: indexOf - Find a substring
The function returns the index position of the first occurrence of the string value passed in cString in the current string by searching forward.
Comparison depends on the string coding type of the calling string. When encoding types between strings differ, a copy of cString is created and recoded to the encoding type of the current string.
When the string has been found,the function returns the absolute position (in units) of the beginning of the searched string. When the search string could not be found, the function returns -1.
odaba::String x = "sticky question";
odaba::String y = "sti";
x.indexOf(y); // returns 0
x.indexOf(y,1); // returns 10
x.indexOf(y,10); // returns 10
x.indexOf(y,11); // returns -1
Not implemented now: search backward for iPosition < 0.
The position of an element in a collection is beginning with 0 for the first element.
Implementation overview
- Find string (case sensitive)
String :: indexOf ( cString ) - Find string
String :: indexOf ( cString, bCaseSensitive ) - Find string at position (case sensitive)
String :: indexOf ( cString, iPosition, bCaseSensitive ) - Find string at position
String :: indexOf ( cString, iPosition )
Implementation details
-
Find string (case sensitive)
int32 String  :: indexOf ( odaba::String &cString )
The function searches the string passed in cString from the beginning of the current string. Comparison is case sensitive.
- cString
- Constant string object
When iPosition exceeds the string length or when the string is empty, the the function returns -1 (lower).
to list
- cString
- Constant string object
-
Find string
int32 String  :: indexOf ( odaba::String &cString, bool bCaseSensitive )
The function searches the string passed in cString from the beginning of the current string.
When bCaseSensitive is true (default), the search is case sensitive; otherwise the search is case insensitive.
- cString
- Constant string object
When iPosition exceeds the string length or when the string is empty, the the function returns -1 (lower).
- bCaseSensitive
- Case sensitive option
The option indicates case sensitive data in text (true)
to list
- cString
- Constant string object
-
Find string at position (case sensitive)
int32 String  :: indexOf ( odaba::String &cString, int32 iPosition, bool bCaseSensitive )
The function searches the string passed in cString beginning at position iPosition (default is 0). When the passed position is greater than the current string length (lengthInUnits()) the function returns -1 (not found). When iPosition is less than zero the function throws an exception.
When bCaseSensitive is true (default), the search is case sensitive; otherwise the search is case insensitive.
- cString
- Constant string object
When iPosition exceeds the string length or when the string is empty, the the function returns -1 (lower).
- iPosition
- Position in collection
The position of an element in a collection is beginning with 0 for the first element.
- bCaseSensitive
- Case sensitive option
The option indicates case sensitive data in text (true)
to list
- cString
- Constant string object
-
Find string at position
int32 String  :: indexOf ( odaba::String &cString, int32 iPosition )
The function searches the string passed in cstring beginning at position iPosition (default is 0). When the passed position is greater than the current string length (lengthInUnits()) the function returns -1 (not found).
The search is case insensitive.
- cString
- Constant string object
When iPosition exceeds the string length or when the string is empty, the the function returns -1 (lower).
- iPosition
- Position in collection
The position of an element in a collection is beginning with 0 for the first element.
to list
- cString
- Constant string object