Click here to Skip to main content
15,879,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to apply " if " condition for checking resulting values has numbers or not
like, the following statement has string value " result " is returning from server and I want to check that, this " result " string contains numbers ( 0-9 ) or not and temp is the barcode string.

i tried with the following , But this gives error, what to do now,


C#
string result = System.Text.Encoding.ASCII.GetString(temp);
int [ ]a ={ 0,1,2,3,4,5,6,7,8,9 } 
if (result.contains(a) == true )
{}
Posted

Depends exactly what you are doing. Normally, this kind of check is to make sure that the string is a number, rather than "contains at least one digit".
You can check by looking at the digits...but I wouldn't.
I'd do this:
C#
string result = System.Text.Encoding.ASCII.GetString(temp);
int value;
if (int.TryParse(result, out value))
   {
   ...
   }

That way, you confirm that it's a valid number (which can include a leading minus sign) and get the value for later use if you need it...which you probably do.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900