如何赋予字符串条件

如何赋予字符串条件

问题描述:



我需要为字符串提供条件,因为字符串不应以"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
}