.NET Framework Class Library
StringStartsWith Method (String, Boolean, CultureInfo)

Determines whether the beginning of this string instance matches the specified string when compared using the specified culture.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)
Syntax
Public Function StartsWith ( _
	value As [%$TOPIC/6k0axhx9_en-us_VS_110_1_0_0_0_0%], _
	ignoreCase As [%$TOPIC/6k0axhx9_en-us_VS_110_1_0_0_0_1%], _
	culture As [%$TOPIC/6k0axhx9_en-us_VS_110_1_0_0_0_2%] _
) As [%$TOPIC/6k0axhx9_en-us_VS_110_1_0_0_0_3%]
public [%$TOPIC/6k0axhx9_en-us_VS_110_1_0_1_0_0%] StartsWith(
	[%$TOPIC/6k0axhx9_en-us_VS_110_1_0_1_0_1%] value,
	[%$TOPIC/6k0axhx9_en-us_VS_110_1_0_1_0_2%] ignoreCase,
	[%$TOPIC/6k0axhx9_en-us_VS_110_1_0_1_0_3%] culture
)
public:
[%$TOPIC/6k0axhx9_en-us_VS_110_1_0_2_0_0%] StartsWith(
	[%$TOPIC/6k0axhx9_en-us_VS_110_1_0_2_0_1%]^ value, 
	[%$TOPIC/6k0axhx9_en-us_VS_110_1_0_2_0_2%] ignoreCase, 
	[%$TOPIC/6k0axhx9_en-us_VS_110_1_0_2_0_3%]^ culture
)
member StartsWith : 
        value:[%$TOPIC/6k0axhx9_en-us_VS_110_1_0_3_0_0%] * 
        ignoreCase:[%$TOPIC/6k0axhx9_en-us_VS_110_1_0_3_0_1%] * 
        culture:[%$TOPIC/6k0axhx9_en-us_VS_110_1_0_3_0_2%] -> [%$TOPIC/6k0axhx9_en-us_VS_110_1_0_3_0_3%]

Parameters

value
Type: SystemString

The string to compare.

ignoreCase
Type: SystemBoolean

true to ignore case during the comparison; otherwise, false.

culture
Type: System.GlobalizationCultureInfo

Cultural information that determines how this string and value are compared. If culture is , the current culture is used.

Return Value

Type: SystemBoolean
true if the value parameter matches the beginning of this string; otherwise, false.
Exceptions
ExceptionCondition
ArgumentNullException

value is .

Remarks

This method compares the value parameter to the substring at the beginning of this string that is the same length as value, and returns a value that indicates whether they are equal. To be equal, value must be an empty string ( StringEmpty), must be a reference to this same instance, or must match the beginning of this instance.

This method performs a comparison using the specified casing and culture.

Examples

The following example determines whether a string occurs at the beginning of another string. The StartsWith method is called several times using case sensitivity, case insensitivity, and different cultures that influence the results of the search.

' This code example demonstrates the  
' System.String.StartsWith(String, ..., CultureInfo) method. 

Imports System
Imports System.Threading
Imports System.Globalization

Class Sample
    Public Shared Sub Main() 
        Dim msg1 As String = "Search for the target string ""{0}"" in the string ""{1}""." & vbCrLf
        Dim msg2 As String = "Using the {0} - ""{1}"" culture:" 
        Dim msg3 As String = "  The string to search ends with the target string: {0}" 
        Dim result As Boolean = False 
        Dim ci As CultureInfo

        ' Define a target string to search for. 
        ' U+00c5 = LATIN CAPITAL LETTER A WITH RING ABOVE 
        Dim capitalARing As String = "Å" 

        ' Define a string to search.  
        ' The result of combining the characters LATIN SMALL LETTER A and COMBINING  
        ' RING ABOVE (U+0061, U+030a) is linguistically equivalent to the character  
        ' LATIN SMALL LETTER A WITH RING ABOVE (U+00e5). 
        Dim aRingXYZ As String = "å" & "xyz" 

        ' Clear the screen and display an introduction.
        Console.Clear()

        ' Display the string to search for and the string to search.
        Console.WriteLine(msg1, capitalARing, aRingXYZ)

        ' Search using English-United States culture.
        ci = New CultureInfo("en-US")
        Console.WriteLine(msg2, ci.DisplayName, ci.Name)

        Console.WriteLine("Case sensitive:")
        result = aRingXYZ.StartsWith(capitalARing, False, ci)
        Console.WriteLine(msg3, result)

        Console.WriteLine("Case insensitive:")
        result = aRingXYZ.StartsWith(capitalARing, True, ci)
        Console.WriteLine(msg3, result)
        Console.WriteLine()

        ' Search using Swedish-Sweden culture.
        ci = New CultureInfo("sv-SE")
        Console.WriteLine(msg2, ci.DisplayName, ci.Name)

        Console.WriteLine("Case sensitive:")
        result = aRingXYZ.StartsWith(capitalARing, False, ci)
        Console.WriteLine(msg3, result)

        Console.WriteLine("Case insensitive:")
        result = aRingXYZ.StartsWith(capitalARing, True, ci)
        Console.WriteLine(msg3, result)

    End Sub 'Main
End Class 'Sample

' 
'Note: This code example was executed on a console whose user interface  
'culture is "en-US" (English-United States). 
' 
'Search for the target string "Å" in the string "a°xyz". 
' 
'Using the English (United States) - "en-US" culture: 
'Case sensitive: 
'  The string to search ends with the target string: False 
'Case insensitive: 
'  The string to search ends with the target string: True 
' 
'Using the Swedish (Sweden) - "sv-SE" culture: 
'Case sensitive: 
'  The string to search ends with the target string: False 
'Case insensitive: 
'  The string to search ends with the target string: False 
'
// This code example demonstrates the  
// System.String.StartsWith(String, ..., CultureInfo) method. 

using System;
using System.Threading;
using System.Globalization;

class Sample 
{
    public static void Main() 
    {
    string msg1 = "Search for the target string \"{0}\" in the string \"{1}\".\n";
    string msg2 = "Using the {0} - \"{1}\" culture:";
    string msg3 = "  The string to search ends with the target string: {0}";
    bool result = false;
    CultureInfo ci;

// Define a target string to search for. 
// U+00c5 = LATIN CAPITAL LETTER A WITH RING ABOVE 
    string capitalARing = "\u00c5";

// Define a string to search.  
// The result of combining the characters LATIN SMALL LETTER A and COMBINING  
// RING ABOVE (U+0061, U+030a) is linguistically equivalent to the character  
// LATIN SMALL LETTER A WITH RING ABOVE (U+00e5). 
    string aRingXYZ = "\u0061\u030a" + "xyz";

// Clear the screen and display an introduction.
    Console.Clear();

// Display the string to search for and the string to search.
    Console.WriteLine(msg1, capitalARing, aRingXYZ);

// Search using English-United States culture.
    ci = new CultureInfo("en-US");
    Console.WriteLine(msg2, ci.DisplayName, ci.Name);

    Console.WriteLine("Case sensitive:");
    result = aRingXYZ.StartsWith(capitalARing, false, ci);
    Console.WriteLine(msg3, result);

    Console.WriteLine("Case insensitive:");
    result = aRingXYZ.StartsWith(capitalARing, true, ci);
    Console.WriteLine(msg3, result);
    Console.WriteLine();

// Search using Swedish-Sweden culture.
    ci = new CultureInfo("sv-SE");
    Console.WriteLine(msg2, ci.DisplayName, ci.Name);

    Console.WriteLine("Case sensitive:");
    result = aRingXYZ.StartsWith(capitalARing, false, ci);
    Console.WriteLine(msg3, result);

    Console.WriteLine("Case insensitive:");
    result = aRingXYZ.StartsWith(capitalARing, true, ci);
    Console.WriteLine(msg3, result);
    }
}

/*
Note: This code example was executed on a console whose user interface 
culture is "en-US" (English-United States).

Search for the target string "�" in the string "a�xyz".

Using the English (United States) - "en-US" culture:
Case sensitive:
  The string to search ends with the target string: False
Case insensitive:
  The string to search ends with the target string: True

Using the Swedish (Sweden) - "sv-SE" culture:
Case sensitive:
  The string to search ends with the target string: False
Case insensitive:
  The string to search ends with the target string: False

*/
Version Information

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.