C# StartsWith() 方法用于检查此字符串实例的开头是否与指定的字符串匹配。
public bool StartsWith(String str) public bool StartsWith(String, Boolean, CultureInfo) public bool StartsWith(String, StringComparison)
str:字符串类型参数,用于检查字符串的开头。
它返回布尔值。
using System;
public class StringExample
{
public static void Main(string[] args)
{
string s1 = "Hello C Sharp";
bool b1 = s1.StartsWith("h");
bool b2 = s1.StartsWith("H");
Console.WriteLine(b1);
Console.WriteLine(b2);
}
}
输出:
False True