开发者

find the numerical value exist in the Expression C#

开发者 https://www.devze.com 2022-12-23 05:05 出处:网络
How do I find: string str=\"(120)(1500)x\"; How to find out in the event that the string contains: string str1=\"()()X\";

How do I find:

string str="(120)(1500)x";

How to find out in the event that the string contains:

string str1="()()X";

I th开发者_运维百科en have to print:

console.writeline("str1 doesnt contain a numerical");


var input = "asdfasfas";
if (!Regex.IsMatch(input, "[0-9]"))
{
    // will occure
}
else
{
    // will not occure
}

var input2 = "asdf123Aasdfasdf";
if (!Regex.IsMatch(input2, "[0-9]"))
{
    // will not occure
}
else
{
    // will occure
}

but remember: this will only check, if there are any digits, not that the string is easily convertable to a number!

more about System.Text.RegularExpressions.Regex.IsMatch()


You can do what you need (wich is quite unclear) with regular expressions (Regex class).


If you don't want to use regular expression, you can find the index of '(' and ')' and calculate if the content is empty.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号