C# 中的 EndsWith() 方法
C# 中的 EndsWith() 方法用于检查当前字符串实例的结尾是否与指定字符串相匹配。
语法
以下是语法 −
public bool EndsWith(string str)
上面,str 参数是要比较的字符串。
示例
现在让我们看一个示例以实现 EndsWith() 方法 −
using System;
public class Demo{
public static void Main(){
bool val;
string str = "demo$";
val = str.EndsWith("$");
Console.WriteLine("Return Value = "+val.ToString());
}
}输出
这将生成以下输出 −
Return Value = True
示例
现在让我们看另一个示例以实现 EndsWith() 方法 −
using System;
public class Demo{
public static void Main(){
bool val;
string str = "mytext@";
val = str.EndsWith("#");
Console.WriteLine("Return Value = "+val.ToString());
}
}输出
这将生成以下输出 −
Return Value = False
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP