Click here to Skip to main content
16,018,418 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a string as 'MR000000001'. Also the string value can vary from 'MR000000001' to 'MR999999999'.
I want to extract the numeric value form that string.

I tried TryParse method but it does not work.
Please help me out.
Thanks in advance.
Posted

Try :
C#
string s = "MR00001012";
int val = int.Parse(s.Substring(2)); // first digit starts at position 2
 
Share this answer
 
v2
Comments
Maciej Los 26-May-15 8:33am    
SubSstring
Mehdi Gholam 26-May-15 9:27am    
Where is intellisense when you need it :)
Maciej Los 26-May-15 13:32pm    
;)
Try regular expression with [0-9]+. There are tons of information present, you just need to google!

Regards,
Asif
 
Share this answer
 
Comments
Maciej Los 26-May-15 13:32pm    
or simple \d+...
+5!

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