C# String StartsWith(String, StringComparison)

Description

String StartsWith(String, StringComparison) determines whether the beginning of this string instance matches the specified string when compared using the specified comparison option.

Syntax

String.StartsWith(String, StringComparison) has the following syntax.


[ComVisibleAttribute(false)]/*from  w ww  .j av  a 2s .  c om*/
public bool StartsWith(
  string value,
  StringComparison comparisonType
)

Parameters

String.StartsWith(String, StringComparison) has the following parameters.

  • value - The string to compare.
  • comparisonType - One of the enumeration values that determines how this string and value are compared.

Returns

String.StartsWith(String, StringComparison) method returns true if this instance begins with value; otherwise, false.

Example

The following example determines whether a string starts with a particular substring.


using System;//from   ww w  .j av  a  2s.  c  om

public class Example
{
    public static void Main()
    {
        Console.WriteLine("java2s.com".StartsWith("java", StringComparison.CurrentCulture));
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version