Searches for the specified character and returns the zero-based index of the first occurrence within the section of the source string that starts at the specified index and contains the specified number of elements using the specified System.Globalization.CompareOptions value.
- source
- The string to search.
- value
- The character to locate within source.
- startIndex
- The zero-based starting index of the search.
- count
- The number of elements in the section to search.
- options
- A value that defines how source and value should be compared. options is either the enumeration value CompareOptions.Ordinal, or a bitwise combination of one or more of the following values: CompareOptions.IgnoreCase, CompareOptions.IgnoreSymbols, CompareOptions.IgnoreNonSpace, CompareOptions.IgnoreWidth, and CompareOptions.IgnoreKanaType.
The zero-based index of the first occurrence of value, if found, within the section of source that starts at startIndex and contains the number of elements specified by count, using the specified comparison options; otherwise, -1. Returns startIndex if value is an ignorable character.
The source string is searched forward starting at startIndex and ending at startIndex + count - 1.
The CompareOptions.StringSort value is not valid for this method.
If options does not include the CompareOptions.Ordinal value, this overload performs a culture-sensitive search. If the character is a Unicode value representing a precomposed character, such as the ligature "Æ" (U+00C6), it might be considered equivalent to any occurrence of its components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. If options includes the CompareOptions.Ordinal value, this overload performs an ordinal (culture-insensitive) search. A character is considered equivalent to another character only if the Unicode values are the same. Overloads of string.IndexOf(char) that search for a character perform an ordinal search, whereas those that search for a string perform a culture-sensitive search.
When possible, you should call string comparison methods that have a parameter of type System.Globalization.CompareOptions to specify the kind of comparison expected. As a general rule, use linguistic options (using the current culture) for comparing strings displayed in the user interface and specify CompareOptions.Ordinal or CompareOptions.OrdinalIgnoreCase for security comparisons.