求截取字符串 h_3.xml 取3r_23.xml 取23h_792.xml 取792h_7374.xml 取7374以上几个文件中,我只需要那几个数字,如何截取呢,格式都一样,就是位数不一样而已,只要那个数字。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 try... Regex reg = new Regex(@"\d+"); MatchCollection mc = reg.Matches(yourStr); foreach (Match m in mc) { richTextBox2.Text += m.Value + "\n"; } System.Text.RegularExpressions.Regex.Match("h_3.xml","\d+").Value; void Main(){string s=@"h_3.xml r_23.xmlh_792.xml h_7374.xml "; foreach(Match m in Regex.Matches(s,@"\d+")) { Console.WriteLine(m.Value); }}/*3237927374*/ string ss = "pp_213.xml";int start=ss.IndexOf("_")+1;int length = ss.IndexOf(".")-start;MessageBox.Show(ss.Substring(start,length)); string result = Regex.Match("h_3.html",@"\d+(?=\D+$)").Value; string[] str = ("h_3.xml,r_23.xml,h_792.xml,h_7374.xml").Split(','); for (int i = 0; i < str.Length; i++) { str[i] = Regex.Match(str[i],@"\d+").Value; //正则获取数值 } C#如何编写程序的升级功能 这段代码获得的CPU序列号重装系统后会变吗? 用C#编程如何实时监测计算机网络流量? 如何取得控件的id 把日文转换为假名有什么思路吗? 如何把一个VC6下做的头文件转换到C#中来? 求解 帮帮忙 [提问]net2.0的dll被4.0的程序或站点引用,底层是使用4.0的core还是2.0的core呢? 为什么执行的时候,没反映? 终于都跳到做C#的工作了,散分! 为什么这两个函数定义时不加static,调用就报错呢? 如何把数组里的内容当作函数来执行!!
MatchCollection mc = reg.Matches(yourStr);
foreach (Match m in mc)
{
richTextBox2.Text += m.Value + "\n";
}
void Main()
{
string s=@"h_3.xml
r_23.xml
h_792.xml
h_7374.xml ";
foreach(Match m in Regex.Matches(s,@"\d+"))
{
Console.WriteLine(m.Value);
}
}
/*
3
23
792
7374
*/
int start=ss.IndexOf("_")+1;
int length = ss.IndexOf(".")-start;
MessageBox.Show(ss.Substring(start,length));
string[] str = ("h_3.xml,r_23.xml,h_792.xml,h_7374.xml").Split(',');
for (int i = 0; i < str.Length; i++) {
str[i] = Regex.Match(str[i],@"\d+").Value; //正则获取数值
}