如何从字符串中拆分数字 [英] how to split number from string

查看:89
本文介绍了如何从字符串中拆分数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有变量



string test = 01XWed



i只想从该字符串中取01





我该怎么办

plz帮帮我

i have variable

string test = 01XWed

i want to take only 01 from that string


how can i do that
plz help me

推荐答案

检查一下: http://www.dotnetperls.com/regex-split-numbers [ ^ ]


正则表达式可能是要走的路:

A regex is probably the way to go:
Match m = Regex.Match("01XWed", "\d+");
if (m.Sucess)
   {
   int value = int.Parse(m.Value);
   ...
   }


public void getNum()
{
	string a = "01xwed";
	string value = "";
	if (a(0).ToString == "0") {
		value = 0;
	}
	value = value + int.Parse(Regex.Replace(a, "[^\\d]", ""));
}



再见


Bye


这篇关于如何从字符串中拆分数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆