📜  C#字符串EndsWith()方法

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

C#字符串EndsWith()

C#EndsWith()方法用于检查指定的字符串是否与此字符串的结尾匹配。如果在此字符串的末尾找到了指定的字符串,则返回true,否则返回false。

签名

public bool EndsWith(String str)
public bool EndsWith(String, Boolean, CultureInfo)
public bool EndsWith (String, StringComparison)?

参量

str:它是一个字符串对象,用于检查指定字符串是否以其结尾。

返回

它返回布尔值true或false。

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

    using System;  
    public class StringExample  
    {  
        public static void Main(string[] args)  
        {  
             string s1 = "Hello";  
             string s2 = "llo";
             string s3 = "C#";
             Console.WriteLine(s1.EndsWith(s2));
             Console.WriteLine(s1.EndsWith(s3));
        }  
    }  

输出:

True
False