C# 确定字符串末尾是否匹配指定子串
代码说明:
C# 确定字符串末尾是否匹配指定子串,本字符串查询实例具体到只匹配字符串开头和结尾是否有指定的字符串,下面是具体的查询代码编写方法: private void button1_Click(object sender, EventArgs e) {//确定字符串开头是否匹配指定子串 string MyFullInfo = "中华人民共和国"; string MyPartInfo="中华"; if(MyFullInfo.StartsWith(MyPartInfo)) MessageBox.Show(MyFullInfo + " 的开头是 " + MyPartInfo, "信息提示", MessageBoxButtons.OK); else MessageBox.Show(MyFullInfo + " 的开头不是 " + MyPartInfo, "信息提示", MessageBoxButtons.OK); } private void button2_Click(object sender, EventArgs e) {//确定字符串末尾是否匹配指定子串 string MyFullInfo = "中华人民共和国"; string MyPartInfo = "共和国"; if (MyFullInfo.EndsWith(MyPartInfo)) MessageBox.Show(MyFullInfo + " 的末尾是 " + MyPartInfo, "信息提示", MessageBoxButtons.OK); else MessageBox.Show(MyFullInfo + " 的末尾不是 " + MyPartInfo, "信息提示", MessageBoxButtons.OK); }
下载说明:请别用迅雷下载,失败请重下,重下不扣分!