當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


C# String 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 




相關用法


注:本文由純淨天空篩選整理自 C# String StartsWith()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。