开发者

find the numerical value exist in the Expression C#

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜