📜  C#字符串StartsWith()方法

📅  最后修改于: 2020-10-31 03:51:18             🧑  作者: Mango

C#字符串StartsWith()

C#StartsWith()方法用于检查此字符串实例的开头是否与指定的字符串相匹配。

签名

public bool StartsWith(String str)
public bool StartsWith(String, Boolean, CultureInfo) 
public bool StartsWith(String, StringComparison)

参数

str:它是字符串类型参数,用于检查字符串的开头。

返回

它返回布尔值。

C#字符串StartsWith()方法示例

    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