views:

55

answers:

3

How do I find:

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

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

string str1="()()X";

I then have to print:

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

+2  A: 
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()

Andreas Niedermair
thanks great help...
glad to hear that! if you found a solution, you might mark that answer properly :)
Andreas Niedermair
He's learning to use SO I guess, here's a +1 from me anyway :p
Stormenet
i know, just wanted to help him and us :) thx
Andreas Niedermair
A: 

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

Andrew Bezzub
A: 

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

Maurizio Reginelli