如何从给定的字符串中提取数值。 [英] How to extract numeric value from a given string.
本文介绍了如何从给定的字符串中提取数值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串'MR000000001'。字符串值也可以从'MR000000001'到'MR999999999'变化。
我想从字符串中提取数值形式。
我试过TryParse方法,但它不起作用。
请帮帮我。
提前谢谢。
解决方案
< blockquote>尝试:
string s = MR00001012;
int val = int .Parse(s.Substring( 2 跨度>)); // 第一个数字从第2位开始
>
使用[0-9] +尝试正则表达式。有大量的信息存在,你只需要谷歌!
问候,
Asif
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.
解决方案
Try :
string s = "MR00001012"; int val = int.Parse(s.Substring(2)); // first digit starts at position 2
Try regular expression with [0-9]+. There are tons of information present, you just need to google!
Regards,
Asif
这篇关于如何从给定的字符串中提取数值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文