Click here to Skip to main content
15,904,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have one string which comes as response from gateway as 'AUTH/TKT T7564B'..
I should take sub string 'T1564B' as my Transaction ID...But in some cases this sub string is just numeric characters only like 'AUTH/TKT 45286'.
Again I should convert that sub string to Integer format...I want to know How to check that sub string for Alphanumeric characters and convert it to int or else throw exception...
Please help soon.....

Thanks
Radhika K
Posted
Updated 23-Aug-12 20:35pm
v2

 
Share this answer
 
Try thisone:
C#
public static Boolean isAlphaNumeric(string strToCheck)
{
    Regex rg = new Regex(@"^[a-zA-Z0-9\s,]*$");
    return rg.IsMatch(strToCheck);
}

It's more undestandable, if you specify in regex, what your string SHOULD contain, and not what it MUST NOT.

In the example above:

List item
^ - means start of the string
[]* - could contain any number of characters between brackets
a-zA-Z0-9 - any alphanumeric characters
\s - any space characters (space/tab/etc.)
, - commas
$ - end of the string
Found it: here[^]

Have a look at many similar threads here[^]
 
Share this answer
 
v2

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