String.StartsWith Method (String, StringComparison)
Determines whether the beginning of this string instance matches the specified string when compared using the specified comparison option.
Assembly: mscorlib (in mscorlib.dll)
[<ComVisibleAttribute(false)>] member StartsWith : value:string * comparisonType:StringComparison -> bool
The string to compare.
One of the enumeration values that determines how this string and value are compared.
Return ValueType: System.Boolean
true if this instance begins with value; otherwise, false.
The StringComparison.CurrentCulture and StringComparison.CurrentCultureIgnoreCase) or the invariant culture (StringComparison.InvariantCulture and StringComparison.InvariantCultureIgnoreCase), or it can consist of a character-by-character comparison of code points (StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase). The comparison can also be case-sensitive (StringComparison.CurrentCulture, StringComparison.InvariantCulture, or StringComparison.Ordinal), or it can ignore case (StringComparison.CurrentCultureIgnoreCase, StringComparison.InvariantCultureIgnoreCase, StringComparison.OrdinalIgnoreCase).method compares the value parameter to the substring at the beginning of this string and returns a value that indicates whether they are equal. To be equal, value must be a reference to this same string, must be the empty string (""), or must match the beginning of this string. The type of comparison performed by the method depends on the value of the comparisonType parameter. The comparison can use the conventions of the current culture (
The following example searches for the string "the" at the beginning of a longer string that begins with the word "The". As the output from the example shows, a call to themethod that performs a culture-insensitive but case-sensitive comparison fails to match the string, while a call that performs a culture- and case-insensitive comparison matches the string.
The following example determines whether a string starts with a particular substring. It initializes a two-dimensional string array. The first element in the second dimension contains a string, and the second element contains the string to search for at the start of the first string. The results are affected by the choice of culture, whether case is ignored, and whether an ordinal comparison is performed. Note that when the string instance contains a ligature, culture-sensitive comparisons with its consecutive characters successfully match.
Available since 8
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 8.1