如何赋予字符串条件 [英] How to give condition for a string

查看:122
本文介绍了如何赋予字符串条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要为字符串提供条件,因为字符串不应以"27"结尾.

我该如何给条件呢?

if(string!= EndsWith("27"))


任何人都可以更正此语法吗?


谢谢
John

Hi,

I need to give condition for a string as string should not end with "27"

How can I give condition for this??

if(string!=EndsWith("27"))


Can anyone please correct this syntax


Thanks
John

推荐答案

string value = "somestring27";
           bool isEndsWith27 = value.EndsWith("27");
           if(isEndsWith27)
           {
               // THe given string ends with 27
           }
           else
           {
               // String doesnt ends with 27
           }



参考: String.EndsWith [



Reference: String.EndsWith[^]


您将字符串变量用作执行测试的对象,如下所示:
You use the string variable as the object you perform the test on, like this:
string myString = "Hello27";
if (!myString.EndsWith("27"))
{
  // Do something
}


这篇关于如何赋予字符串条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆