C# 属性

C# 抽象

C# 字符串

C# 泛型

C# 杂项

C# 新特性

C# StartsWith() 检查匹配字符串

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

签名

句法 (Syntax)

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

范围

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

返回

它返回布尔值。


C# String StartsWith() 方法示例

例子 (Example)

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


  • 使用社交账号登录,本站支持
全部评论(0)