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)] public: bool StartsWith( String^ value, StringComparison comparisonType )
Parameters
- value
- Type: System::String
The string to compare.
- comparisonType
- Type: System::StringComparison
One of the enumeration values that determines how this string and value are compared.
| Exception | Condition |
|---|---|
| ArgumentNullException | value is nullptr. |
| ArgumentException | comparisonType is not a StringComparison value. |
The StartsWith 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 StartsWith method depends on the value of the comparisonType parameter. The comparison can use the conventions of the current culture (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).
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.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.