C#中如何提取字符串中的数字
哪位大哥教教我,像如下字符串"47.64483, -122.141197"
如何将两个数字提取出来? --------------------编程问答-------------------- "47.64483, -122.141197".Split("|") --------------------编程问答--------------------
"47.64483, -122.141197".Split(",") --------------------编程问答-------------------- string result=Regex.Replace(str,"\\D+",""); --------------------编程问答--------------------
--------------------编程问答--------------------
string str = "47.64483, -122.141197";
string[] arr = str.Split(',');
--------------------编程问答-------------------- 原来是这种,看标题以为是混合字符串了 --------------------编程问答--------------------
string source = "47.64483, -122.141197";
Regex reg = new Regex(@"-?[\d]+.?[\d]+");
Match mm = reg.Match(source);
MatchCollection mc = reg.Matches(source);
foreach (Match m in mc)
{
MessageBox.Show(m.Value);
}
我写的太简单了,以后一定改
--------------------编程问答-------------------- --------------------编程问答-------------------- "47.64483, -122.141197".Split("|")
string numstr = "47.64483, -122.141197";
string[] num = numstr.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
吃不消了 --------------------编程问答--------------------
+1
补充:.NET技术 , C#