会 c# 截取字符串 请来!!! c#字符串 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string[] a = { "42MSE0180X0544.5X020M", "42MSE0180X0550X060M", "42MSE0196X0300X025L", "42MSE0194X0400X015", "42MSE0200X0350X115" }; int[] b = { 0, 0, 0, 0, 0 }; for (int i = 0; i < a.Length; i++) { int xpos = a[i].LastIndexOf("X");//最后一个X位置 string r = a[i].Substring(xpos + 1);//后半部分 r = System.Text.RegularExpressions.Regex.Replace(r, @"[^\d]+", ""); b[i] = int.Parse(r); } b[i] = int.Parse(r); 改成int.TryParse(r, out b[i]); 如果这个位置可能出现小数点,还要改一下r = System.Text.RegularExpressions.Regex.Replace(r, @"[^\d]+", ""); 改成r = System.Text.RegularExpressions.Regex.Replace(r, @"[\.^\d]+", ""); (?<=M)这是什么意思?\d+这个我知道,取数字 r = System.Text.RegularExpressions.Regex.Replace(r, @"[\.^\d]+", ""); 这个应该是这样 r = System.Text.RegularExpressions.Regex.Replace(r, @"[^\d\.]+", ""); static ArrayList get() { ArrayList list = new ArrayList(); string[] strList = { "42MSE0180X0544.5X020M", "42MSE0180X0550X060M", "42MSE0196X0300X025L", "42MSE0194X0400X015", "42MSE0200X0350X115" }; if (null != strList && strList.Length > 0) { for (int i = 0; i < strList.Length; i++) { int inStr = strList[i].LastIndexOf("X"); string str = strList[i].Substring(inStr + 1, 3); if (!string.IsNullOrEmpty(str)) { list.Add(str); } } } return list; } 请教:自己扩展的RichTextBox实现插入QQ表情(附源码)的问题 请问如何解决数据库备份问题 泛型的使用 作好的程序像QQ一样,只在右下角显示 怎样遍历一个ILIST集合 并将其所有的数据插入到表中 分页 你们的项目开发使用平台工具吗? 为何检测不到我的CheckBox控件,始终为false 喜欢传奇世界的过来侃看看哦 水晶报表打印问题? C# 如何通过USB数据线传输一电脑上指定文件到另一电脑上 每次打开VS2010时怎么老是弹出这个窗口,求大神解决
string[] a = { "42MSE0180X0544.5X020M", "42MSE0180X0550X060M", "42MSE0196X0300X025L", "42MSE0194X0400X015", "42MSE0200X0350X115" };
int[] b = { 0, 0, 0, 0, 0 };
for (int i = 0; i < a.Length; i++)
{
int xpos = a[i].LastIndexOf("X");//最后一个X位置
string r = a[i].Substring(xpos + 1);//后半部分
r = System.Text.RegularExpressions.Regex.Replace(r, @"[^\d]+", "");
b[i] = int.Parse(r);
}
改成
int.TryParse(r, out b[i]);
r = System.Text.RegularExpressions.Regex.Replace(r, @"[^\d]+", "");
改成
r = System.Text.RegularExpressions.Regex.Replace(r, @"[\.^\d]+", "");
{
ArrayList list = new ArrayList(); string[] strList = { "42MSE0180X0544.5X020M", "42MSE0180X0550X060M", "42MSE0196X0300X025L", "42MSE0194X0400X015", "42MSE0200X0350X115" };
if (null != strList && strList.Length > 0)
{
for (int i = 0; i < strList.Length; i++)
{
int inStr = strList[i].LastIndexOf("X");
string str = strList[i].Substring(inStr + 1, 3);
if (!string.IsNullOrEmpty(str))
{
list.Add(str);
}
}
} return list;
}