PDA

Click to See Complete Forum and Search --> : if statement


carstenht
Mar 7th, 2007, 09:38 AM
if i have the following array:

private string[] digits = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };


and i then want to check if a string contains any of these numbers, could i do something like this:




String test ="1+2+3";

if(test equals any of the digits in 'digits')
{
// Do stuff
}

daveStudent
Mar 7th, 2007, 09:57 AM
i would use regular expressions

you need to add the following

using System.Text.RegularExpressions;



the actual code would be:

String strInput = "Your input text!!!11";
string strPatern = "[0-9]";
Match myMatch = Regex.Match(strInput, strPatern);
if(myMatch.Success)
{
//dostuff
}

carstenht
Mar 7th, 2007, 10:00 AM
Thanks ;) ill try it out

carstenht
Mar 7th, 2007, 10:02 AM
Just ran into a snare...how about + - and *??

daveStudent
Mar 7th, 2007, 10:34 AM
Just ran into a snare...how about + - and *??


think i answered that in your other thread :)