CompareInfo.IndexOf Method (String, String, Int32, CompareOptions)
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Searches for the specified substring and returns the zero-based index of the first occurrence within the section of the source string that extends from the specified index to the end of the string using the specified CompareOptions value.
Namespace: System.Globalization
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public Overridable Function IndexOf ( _
source As String, _
value As String, _
startIndex As Integer, _
options As CompareOptions _
) As Integer
public virtual int IndexOf(
string source,
string value,
int startIndex,
CompareOptions options
)
Parameters
- source
Type: System.String
The string to search.
- value
Type: System.String
The string to locate within source.
- startIndex
Type: System.Int32
The zero-based starting index of the search.
- options
Type: System.Globalization.CompareOptions
The CompareOptions value that defines how source and value should be compared. options is either the value Ordinal used by itself, or the bitwise combination of one or more of the following values: IgnoreCase, IgnoreSymbols, IgnoreNonSpace, IgnoreWidth, and IgnoreKanaType.
Return Value
Type: System.Int32
The zero-based index of the first occurrence of value within the section of source that extends from startIndex to the end of source using the specified CompareOptions value, if found; otherwise, -1.
Exceptions
Exception | Condition |
---|---|
ArgumentNullException | source is nulla null reference (Nothing in Visual Basic). -or- value is nulla null reference (Nothing in Visual Basic). |
ArgumentOutOfRangeException | startIndex is outside the range of valid indexes for source. |
ArgumentException | options contains an invalid CompareOptions value. |
Remarks
The source string is searched forward starting at startIndex and ending at the end of the string.
The CompareOptions.StringSort value is not valid for this method.
If options does not include the Ordinal value, this overload performs a culture-sensitive search. A Unicode value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. If options includes the Ordinal value, this overload performs an ordinal (culture-insensitive) search, where the Unicode values are compared.
Examples
The following example determines the indexes of the first and last occurrences of a character or a substring within a portion of a string. Note that IndexOf and LastIndexOf are searching in different portions of the string, even with the same startIndex parameter.
Imports System.Globalization
Public Class Example
Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
' Creates CompareInfo for the InvariantCulture.
Dim myComp As CompareInfo = CultureInfo.InvariantCulture.CompareInfo
' iS is the starting index of the substring.
Dim [iS] As Integer = 20
' myT1 is the string used for padding.
Dim myT1 As [String]
' Searches for the ligature Æ.
Dim myStr As [String] = "Is AE or ae the same as Æ or æ?"
outputBlock.Text &= vbCrLf
myT1 = New [String]("-"c, [iS])
outputBlock.Text += String.Format("IndexOf( String, *, {0}, * )", [iS]) & vbCrLf
outputBlock.Text += String.Format("Original : {0}", myStr) & vbCrLf
outputBlock.Text += String.Format("No options : {0}{1}", myT1, myStr.Substring([iS])) & vbCrLf
PrintMarker(outputBlock, " AE : ", myComp.IndexOf(myStr, "AE", [iS], CompareOptions.None), -1)
PrintMarker(outputBlock, " ae : ", myComp.IndexOf(myStr, "ae", [iS], CompareOptions.None), -1)
PrintMarker(outputBlock, " Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS], CompareOptions.None), -1)
PrintMarker(outputBlock, " æ : ", myComp.IndexOf(myStr, "æ"c, [iS], CompareOptions.None), -1)
outputBlock.Text += String.Format("Ordinal : {0}{1}", myT1, myStr.Substring([iS])) & vbCrLf
PrintMarker(outputBlock, " AE : ", myComp.IndexOf(myStr, "AE", [iS], CompareOptions.Ordinal), -1)
PrintMarker(outputBlock, " ae : ", myComp.IndexOf(myStr, "ae", [iS], CompareOptions.Ordinal), -1)
PrintMarker(outputBlock, " Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS], CompareOptions.Ordinal), -1)
PrintMarker(outputBlock, " æ : ", myComp.IndexOf(myStr, "æ"c, [iS], CompareOptions.Ordinal), -1)
outputBlock.Text += String.Format("IgnoreCase : {0}{1}", myT1, myStr.Substring([iS])) & vbCrLf
PrintMarker(outputBlock, " AE : ", myComp.IndexOf(myStr, "AE", [iS], CompareOptions.IgnoreCase), -1)
PrintMarker(outputBlock, " ae : ", myComp.IndexOf(myStr, "ae", [iS], CompareOptions.IgnoreCase), -1)
PrintMarker(outputBlock, " Æ : ", myComp.IndexOf(myStr, "Æ"c, [iS], CompareOptions.IgnoreCase), -1)
PrintMarker(outputBlock, " æ : ", myComp.IndexOf(myStr, "æ"c, [iS], CompareOptions.IgnoreCase), -1)
myT1 = New [String]("-"c, myStr.Length - [iS] - 1)
outputBlock.Text += String.Format("LastIndexOf( String, *, {0}, * )", [iS]) & vbCrLf
outputBlock.Text += String.Format("Original : {0}", myStr) & vbCrLf
outputBlock.Text += String.Format("No options : {0}{1}", myStr.Substring(0, [iS] + 1), myT1) & vbCrLf
PrintMarker(outputBlock, " AE : ", -1, myComp.LastIndexOf(myStr, "AE", [iS], CompareOptions.None))
PrintMarker(outputBlock, " ae : ", -1, myComp.LastIndexOf(myStr, "ae", [iS], CompareOptions.None))
PrintMarker(outputBlock, " Æ : ", -1, myComp.LastIndexOf(myStr, "Æ"c, [iS], CompareOptions.None))
PrintMarker(outputBlock, " æ : ", -1, myComp.LastIndexOf(myStr, "æ"c, [iS], CompareOptions.None))
outputBlock.Text += String.Format("Ordinal : {0}{1}", myStr.Substring(0, [iS] + 1), myT1) & vbCrLf
PrintMarker(outputBlock, " AE : ", -1, myComp.LastIndexOf(myStr, "AE", [iS], CompareOptions.Ordinal))
PrintMarker(outputBlock, " ae : ", -1, myComp.LastIndexOf(myStr, "ae", [iS], CompareOptions.Ordinal))
PrintMarker(outputBlock, " Æ : ", -1, myComp.LastIndexOf(myStr, "Æ"c, [iS], CompareOptions.Ordinal))
PrintMarker(outputBlock, " æ : ", -1, myComp.LastIndexOf(myStr, "æ"c, [iS], CompareOptions.Ordinal))
outputBlock.Text += String.Format("IgnoreCase : {0}{1}", myStr.Substring(0, [iS] + 1), myT1) & vbCrLf
PrintMarker(outputBlock, " AE : ", -1, myComp.LastIndexOf(myStr, "AE", [iS], CompareOptions.IgnoreCase))
PrintMarker(outputBlock, " ae : ", -1, myComp.LastIndexOf(myStr, "ae", [iS], CompareOptions.IgnoreCase))
PrintMarker(outputBlock, " Æ : ", -1, myComp.LastIndexOf(myStr, "Æ"c, [iS], CompareOptions.IgnoreCase))
PrintMarker(outputBlock, " æ : ", -1, myComp.LastIndexOf(myStr, "æ"c, [iS], CompareOptions.IgnoreCase))
' Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
myStr = "Is " & ChrW(&H55) & ChrW(&H308) & " or " & ChrW(&H75) & ChrW(&H308) & " the same as " & ChrW(&HDC) & " or " & ChrW(&HFC) & "?"
outputBlock.Text &= vbCrLf
myT1 = New [String]("-"c, [iS])
outputBlock.Text += String.Format("IndexOf( String, *, {0}, * )", [iS]) & vbCrLf
outputBlock.Text += String.Format("Original : {0}", myStr) & vbCrLf
outputBlock.Text += String.Format("No options : {0}{1}", myT1, myStr.Substring([iS])) & vbCrLf
PrintMarker(outputBlock, " U" & ChrW(&H308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H308), [iS], CompareOptions.None), -1)
PrintMarker(outputBlock, " u" & ChrW(&H308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H308), [iS], CompareOptions.None), -1)
PrintMarker(outputBlock, " Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS], CompareOptions.None), -1)
PrintMarker(outputBlock, " ü : ", myComp.IndexOf(myStr, "ü"c, [iS], CompareOptions.None), -1)
outputBlock.Text += String.Format("Ordinal : {0}{1}", myT1, myStr.Substring([iS])) & vbCrLf
PrintMarker(outputBlock, " U" & ChrW(&H308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H308), [iS], CompareOptions.Ordinal), -1)
PrintMarker(outputBlock, " u" & ChrW(&H308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H308), [iS], CompareOptions.Ordinal), -1)
PrintMarker(outputBlock, " Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS], CompareOptions.Ordinal), -1)
PrintMarker(outputBlock, " ü : ", myComp.IndexOf(myStr, "ü"c, [iS], CompareOptions.Ordinal), -1)
outputBlock.Text += String.Format("IgnoreCase : {0}{1}", myT1, myStr.Substring([iS])) & vbCrLf
PrintMarker(outputBlock, " U" & ChrW(&H308) & " : ", myComp.IndexOf(myStr, "U" & ChrW(&H308), [iS], CompareOptions.IgnoreCase), -1)
PrintMarker(outputBlock, " u" & ChrW(&H308) & " : ", myComp.IndexOf(myStr, "u" & ChrW(&H308), [iS], CompareOptions.IgnoreCase), -1)
PrintMarker(outputBlock, " Ü : ", myComp.IndexOf(myStr, "Ü"c, [iS], CompareOptions.IgnoreCase), -1)
PrintMarker(outputBlock, " ü : ", myComp.IndexOf(myStr, "ü"c, [iS], CompareOptions.IgnoreCase), -1)
myT1 = New [String]("-"c, myStr.Length - [iS] - 1)
outputBlock.Text += String.Format("LastIndexOf( String, *, {0}, * )", [iS]) & vbCrLf
outputBlock.Text += String.Format("Original : {0}", myStr) & vbCrLf
outputBlock.Text += String.Format("No options : {0}{1}", myStr.Substring(0, [iS] + 1), myT1) & vbCrLf
PrintMarker(outputBlock, " U" & ChrW(&H308) & " : ", -1, myComp.LastIndexOf(myStr, "U" & ChrW(&H308), [iS], CompareOptions.None))
PrintMarker(outputBlock, " u" & ChrW(&H308) & " : ", -1, myComp.LastIndexOf(myStr, "u" & ChrW(&H308), [iS], CompareOptions.None))
PrintMarker(outputBlock, " Ü : ", -1, myComp.LastIndexOf(myStr, "Ü"c, [iS], CompareOptions.None))
PrintMarker(outputBlock, " ü : ", -1, myComp.LastIndexOf(myStr, "ü"c, [iS], CompareOptions.None))
outputBlock.Text += String.Format("Ordinal : {0}{1}", myStr.Substring(0, [iS] + 1), myT1) & vbCrLf
PrintMarker(outputBlock, " U" & ChrW(&H308) & " : ", -1, myComp.LastIndexOf(myStr, "U" & ChrW(&H308), [iS], CompareOptions.Ordinal))
PrintMarker(outputBlock, " u" & ChrW(&H308) & " : ", -1, myComp.LastIndexOf(myStr, "u" & ChrW(&H308), [iS], CompareOptions.Ordinal))
PrintMarker(outputBlock, " Ü : ", -1, myComp.LastIndexOf(myStr, "Ü"c, [iS], CompareOptions.Ordinal))
PrintMarker(outputBlock, " ü : ", -1, myComp.LastIndexOf(myStr, "ü"c, [iS], CompareOptions.Ordinal))
outputBlock.Text += String.Format("IgnoreCase : {0}{1}", myStr.Substring(0, [iS] + 1), myT1) & vbCrLf
PrintMarker(outputBlock, " U" & ChrW(&H308) & " : ", -1, myComp.LastIndexOf(myStr, "U" & ChrW(&H308), [iS], CompareOptions.IgnoreCase))
PrintMarker(outputBlock, " u" & ChrW(&H308) & " : ", -1, myComp.LastIndexOf(myStr, "u" & ChrW(&H308), [iS], CompareOptions.IgnoreCase))
PrintMarker(outputBlock, " Ü : ", -1, myComp.LastIndexOf(myStr, "Ü"c, [iS], CompareOptions.IgnoreCase))
PrintMarker(outputBlock, " ü : ", -1, myComp.LastIndexOf(myStr, "ü"c, [iS], CompareOptions.IgnoreCase))
End Sub 'Main
Public Shared Sub PrintMarker(ByVal outputBlock As System.Windows.Controls.TextBlock, ByVal Prefix As [String], ByVal First As Integer, ByVal Last As Integer)
' Determines the size of the array to create.
Dim mySize As Integer
If Last > First Then
mySize = Last
Else
mySize = First
End If
If mySize > -1 Then
' Creates an array of Char to hold the markers.
Dim myCharArr(mySize + 1) As [Char]
' Inserts the appropriate markers.
If First > -1 Then
myCharArr(First) = "f"c
End If
If Last > -1 Then
myCharArr(Last) = "l"c
End If
If First = Last Then
myCharArr(First) = "b"c
End If
' Displays the array of Char as a String.
outputBlock.Text += String.Format("{0}{1}", Prefix, New [String](myCharArr)) & vbCrLf
Else
outputBlock.Text &= Prefix & vbCrLf
End If
End Sub 'PrintMarker
End Class 'SamplesCompareInfo
'This code produces the following output.
'
'IndexOf( String, *, 20, * )
'Original : Is AE or ae the same as Æ or æ?
'No options : -------------------- as Æ or æ?
' AE : f
' ae : f
' Æ : f
' æ : f
'Ordinal : -------------------- as Æ or æ?
' AE :
' ae :
' Æ : f
' æ : f
'IgnoreCase : -------------------- as Æ or æ?
' AE : f
' ae : f
' Æ : f
' æ : f
'LastIndexOf( String, *, 20, * )
'Original : Is AE or ae the same as Æ or æ?
'No options : Is AE or ae the same ----------
' AE : l
' ae : l
' Æ : l
' æ : l
'Ordinal : Is AE or ae the same ----------
' AE : l
' ae : l
' Æ :
' æ :
'IgnoreCase : Is AE or ae the same ----------
' AE : l
' ae : l
' Æ : l
' æ : l
'
'IndexOf( String, *, 20, * )
'Original : Is U" or u" the same as Ü or ü?
'No options : -------------------- as Ü or ü?
' U" : f
' u" : f
' Ü : f
' ü : f
'Ordinal : -------------------- as Ü or ü?
' U" :
' u" :
' Ü : f
' ü : f
'IgnoreCase : -------------------- as Ü or ü?
' U" : f
' u" : f
' Ü : f
' ü : f
'LastIndexOf( String, *, 20, * )
'Original : Is U" or u" the same as Ü or ü?
'No options : Is U" or u" the same ----------
' U" : l
' u" : l
' Ü : l
' ü : l
'Ordinal : Is U" or u" the same ----------
' U" : l
' u" : l
' Ü :
' ü :
'IgnoreCase : Is U" or u" the same ----------
' U" : l
' u" : l
' Ü : l
' ü : l
using System;
using System.Globalization;
public class Example
{
public static void Demo(System.Windows.Controls.TextBlock outputBlock)
{
// Creates CompareInfo for the InvariantCulture.
CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo;
// iS is the starting index of the substring.
int iS = 20;
// myT1 is the string used for padding.
String myT1;
// Searches for the ligature Æ.
String myStr = "Is AE or ae the same as Æ or æ?";
outputBlock.Text += "\n";
myT1 = new String('-', iS);
outputBlock.Text += String.Format("IndexOf( String, *, {0}, * )", iS) + "\n";
outputBlock.Text += String.Format("Original : {0}", myStr) + "\n";
outputBlock.Text += String.Format("No options : {0}{1}", myT1, myStr.Substring(iS)) + "\n";
PrintMarker(outputBlock, " AE : ", myComp.IndexOf(myStr, "AE", iS, CompareOptions.None), -1);
PrintMarker(outputBlock, " ae : ", myComp.IndexOf(myStr, "ae", iS, CompareOptions.None), -1);
PrintMarker(outputBlock, " Æ : ", myComp.IndexOf(myStr, 'Æ', iS, CompareOptions.None), -1);
PrintMarker(outputBlock, " æ : ", myComp.IndexOf(myStr, 'æ', iS, CompareOptions.None), -1);
outputBlock.Text += String.Format("Ordinal : {0}{1}", myT1, myStr.Substring(iS)) + "\n";
PrintMarker(outputBlock, " AE : ", myComp.IndexOf(myStr, "AE", iS, CompareOptions.Ordinal), -1);
PrintMarker(outputBlock, " ae : ", myComp.IndexOf(myStr, "ae", iS, CompareOptions.Ordinal), -1);
PrintMarker(outputBlock, " Æ : ", myComp.IndexOf(myStr, 'Æ', iS, CompareOptions.Ordinal), -1);
PrintMarker(outputBlock, " æ : ", myComp.IndexOf(myStr, 'æ', iS, CompareOptions.Ordinal), -1);
outputBlock.Text += String.Format("IgnoreCase : {0}{1}", myT1, myStr.Substring(iS)) + "\n";
PrintMarker(outputBlock, " AE : ", myComp.IndexOf(myStr, "AE", iS, CompareOptions.IgnoreCase), -1);
PrintMarker(outputBlock, " ae : ", myComp.IndexOf(myStr, "ae", iS, CompareOptions.IgnoreCase), -1);
PrintMarker(outputBlock, " Æ : ", myComp.IndexOf(myStr, 'Æ', iS, CompareOptions.IgnoreCase), -1);
PrintMarker(outputBlock, " æ : ", myComp.IndexOf(myStr, 'æ', iS, CompareOptions.IgnoreCase), -1);
myT1 = new String('-', myStr.Length - iS - 1);
outputBlock.Text += String.Format("LastIndexOf( String, *, {0}, * )", iS) + "\n";
outputBlock.Text += String.Format("Original : {0}", myStr) + "\n";
outputBlock.Text += String.Format("No options : {0}{1}", myStr.Substring(0, iS + 1), myT1) + "\n";
PrintMarker(outputBlock, " AE : ", -1, myComp.LastIndexOf(myStr, "AE", iS, CompareOptions.None));
PrintMarker(outputBlock, " ae : ", -1, myComp.LastIndexOf(myStr, "ae", iS, CompareOptions.None));
PrintMarker(outputBlock, " Æ : ", -1, myComp.LastIndexOf(myStr, 'Æ', iS, CompareOptions.None));
PrintMarker(outputBlock, " æ : ", -1, myComp.LastIndexOf(myStr, 'æ', iS, CompareOptions.None));
outputBlock.Text += String.Format("Ordinal : {0}{1}", myStr.Substring(0, iS + 1), myT1) + "\n";
PrintMarker(outputBlock, " AE : ", -1, myComp.LastIndexOf(myStr, "AE", iS, CompareOptions.Ordinal));
PrintMarker(outputBlock, " ae : ", -1, myComp.LastIndexOf(myStr, "ae", iS, CompareOptions.Ordinal));
PrintMarker(outputBlock, " Æ : ", -1, myComp.LastIndexOf(myStr, 'Æ', iS, CompareOptions.Ordinal));
PrintMarker(outputBlock, " æ : ", -1, myComp.LastIndexOf(myStr, 'æ', iS, CompareOptions.Ordinal));
outputBlock.Text += String.Format("IgnoreCase : {0}{1}", myStr.Substring(0, iS + 1), myT1) + "\n";
PrintMarker(outputBlock, " AE : ", -1, myComp.LastIndexOf(myStr, "AE", iS, CompareOptions.IgnoreCase));
PrintMarker(outputBlock, " ae : ", -1, myComp.LastIndexOf(myStr, "ae", iS, CompareOptions.IgnoreCase));
PrintMarker(outputBlock, " Æ : ", -1, myComp.LastIndexOf(myStr, 'Æ', iS, CompareOptions.IgnoreCase));
PrintMarker(outputBlock, " æ : ", -1, myComp.LastIndexOf(myStr, 'æ', iS, CompareOptions.IgnoreCase));
// Searches for the combining character sequence Latin capital letter U with diaeresis or Latin small letter u with diaeresis.
myStr = "Is \u0055\u0308 or \u0075\u0308 the same as \u00DC or \u00FC?";
outputBlock.Text += "\n";
myT1 = new String('-', iS);
outputBlock.Text += String.Format("IndexOf( String, *, {0}, * )", iS) + "\n";
outputBlock.Text += String.Format("Original : {0}", myStr) + "\n";
outputBlock.Text += String.Format("No options : {0}{1}", myT1, myStr.Substring(iS)) + "\n";
PrintMarker(outputBlock, " U\u0308 : ", myComp.IndexOf(myStr, "U\u0308", iS, CompareOptions.None), -1);
PrintMarker(outputBlock, " u\u0308 : ", myComp.IndexOf(myStr, "u\u0308", iS, CompareOptions.None), -1);
PrintMarker(outputBlock, " Ü : ", myComp.IndexOf(myStr, 'Ü', iS, CompareOptions.None), -1);
PrintMarker(outputBlock, " ü : ", myComp.IndexOf(myStr, 'ü', iS, CompareOptions.None), -1);
outputBlock.Text += String.Format("Ordinal : {0}{1}", myT1, myStr.Substring(iS)) + "\n";
PrintMarker(outputBlock, " U\u0308 : ", myComp.IndexOf(myStr, "U\u0308", iS, CompareOptions.Ordinal), -1);
PrintMarker(outputBlock, " u\u0308 : ", myComp.IndexOf(myStr, "u\u0308", iS, CompareOptions.Ordinal), -1);
PrintMarker(outputBlock, " Ü : ", myComp.IndexOf(myStr, 'Ü', iS, CompareOptions.Ordinal), -1);
PrintMarker(outputBlock, " ü : ", myComp.IndexOf(myStr, 'ü', iS, CompareOptions.Ordinal), -1);
outputBlock.Text += String.Format("IgnoreCase : {0}{1}", myT1, myStr.Substring(iS)) + "\n";
PrintMarker(outputBlock, " U\u0308 : ", myComp.IndexOf(myStr, "U\u0308", iS, CompareOptions.IgnoreCase), -1);
PrintMarker(outputBlock, " u\u0308 : ", myComp.IndexOf(myStr, "u\u0308", iS, CompareOptions.IgnoreCase), -1);
PrintMarker(outputBlock, " Ü : ", myComp.IndexOf(myStr, 'Ü', iS, CompareOptions.IgnoreCase), -1);
PrintMarker(outputBlock, " ü : ", myComp.IndexOf(myStr, 'ü', iS, CompareOptions.IgnoreCase), -1);
myT1 = new String('-', myStr.Length - iS - 1);
outputBlock.Text += String.Format("LastIndexOf( String, *, {0}, * )", iS) + "\n";
outputBlock.Text += String.Format("Original : {0}", myStr) + "\n";
outputBlock.Text += String.Format("No options : {0}{1}", myStr.Substring(0, iS + 1), myT1) + "\n";
PrintMarker(outputBlock, " U\u0308 : ", -1, myComp.LastIndexOf(myStr, "U\u0308", iS, CompareOptions.None));
PrintMarker(outputBlock, " u\u0308 : ", -1, myComp.LastIndexOf(myStr, "u\u0308", iS, CompareOptions.None));
PrintMarker(outputBlock, " Ü : ", -1, myComp.LastIndexOf(myStr, 'Ü', iS, CompareOptions.None));
PrintMarker(outputBlock, " ü : ", -1, myComp.LastIndexOf(myStr, 'ü', iS, CompareOptions.None));
outputBlock.Text += String.Format("Ordinal : {0}{1}", myStr.Substring(0, iS + 1), myT1) + "\n";
PrintMarker(outputBlock, " U\u0308 : ", -1, myComp.LastIndexOf(myStr, "U\u0308", iS, CompareOptions.Ordinal));
PrintMarker(outputBlock, " u\u0308 : ", -1, myComp.LastIndexOf(myStr, "u\u0308", iS, CompareOptions.Ordinal));
PrintMarker(outputBlock, " Ü : ", -1, myComp.LastIndexOf(myStr, 'Ü', iS, CompareOptions.Ordinal));
PrintMarker(outputBlock, " ü : ", -1, myComp.LastIndexOf(myStr, 'ü', iS, CompareOptions.Ordinal));
outputBlock.Text += String.Format("IgnoreCase : {0}{1}", myStr.Substring(0, iS + 1), myT1) + "\n";
PrintMarker(outputBlock, " U\u0308 : ", -1, myComp.LastIndexOf(myStr, "U\u0308", iS, CompareOptions.IgnoreCase));
PrintMarker(outputBlock, " u\u0308 : ", -1, myComp.LastIndexOf(myStr, "u\u0308", iS, CompareOptions.IgnoreCase));
PrintMarker(outputBlock, " Ü : ", -1, myComp.LastIndexOf(myStr, 'Ü', iS, CompareOptions.IgnoreCase));
PrintMarker(outputBlock, " ü : ", -1, myComp.LastIndexOf(myStr, 'ü', iS, CompareOptions.IgnoreCase));
}
public static void PrintMarker(System.Windows.Controls.TextBlock outputBlock, String Prefix, int First, int Last)
{
// Determines the size of the array to create.
int mySize;
if (Last > First)
mySize = Last;
else
mySize = First;
if (mySize > -1)
{
// Creates an array of Char to hold the markers.
Char[] myCharArr = new Char[mySize + 1];
// Inserts the appropriate markers.
if (First > -1)
myCharArr[First] = 'f';
if (Last > -1)
myCharArr[Last] = 'l';
if (First == Last)
myCharArr[First] = 'b';
// Displays the array of Char as a String.
outputBlock.Text += String.Format("{0}{1}", Prefix, new String(myCharArr)) + "\n";
}
else
outputBlock.Text += Prefix + "\n";
}
}
/*
This code produces the following output.
IndexOf( String, *, 20, * )
Original : Is AE or ae the same as Æ or æ?
No options : -------------------- as Æ or æ?
AE : f
ae : f
Æ : f
æ : f
Ordinal : -------------------- as Æ or æ?
AE :
ae :
Æ : f
æ : f
IgnoreCase : -------------------- as Æ or æ?
AE : f
ae : f
Æ : f
æ : f
LastIndexOf( String, *, 20, * )
Original : Is AE or ae the same as Æ or æ?
No options : Is AE or ae the same ----------
AE : l
ae : l
Æ : l
æ : l
Ordinal : Is AE or ae the same ----------
AE : l
ae : l
Æ :
æ :
IgnoreCase : Is AE or ae the same ----------
AE : l
ae : l
Æ : l
æ : l
IndexOf( String, *, 20, * )
Original : Is U" or u" the same as Ü or ü?
No options : -------------------- as Ü or ü?
U" : f
u" : f
Ü : f
ü : f
Ordinal : -------------------- as Ü or ü?
U" :
u" :
Ü : f
ü : f
IgnoreCase : -------------------- as Ü or ü?
U" : f
u" : f
Ü : f
ü : f
LastIndexOf( String, *, 20, * )
Original : Is U" or u" the same as Ü or ü?
No options : Is U" or u" the same ----------
U" : l
u" : l
Ü : l
ü : l
Ordinal : Is U" or u" the same ----------
U" : l
u" : l
Ü :
ü :
IgnoreCase : Is U" or u" the same ----------
U" : l
u" : l
Ü : l
ü : l
*/
Version Information
Silverlight
Supported in: 5, 4, 3
Silverlight for Windows Phone
Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0
XNA Framework
Supported in: Xbox 360, Windows Phone OS 7.0
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
See Also