不定长但固定格式的字符串折分问题 本帖最后由 dovefay 于 2009-11-23 09:36:30 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string s = "iphone;motorala;LG;nokia;samsung;sony;2009-11-11_2010-12-12"; string[] arr = s.Split(new char[] { ';' }); string[] date = arr[arr.Length - 1].Split(new char[] { '_' }); Response.Write(date[0] + "||" + date[1]);试试这个,也就是多截一次 string[] array = Regex.Split(input, @"[;_](?=\d)"); 如 果 前 面 的 字 符 串 中 没 有 "sony;1nokia;"这 样 的 格 式 .空 军 的 正 则 完 全 可 以 用 ..如 果 有 的 话 ,就 会 把 1nokia也 提 出 来 ..可 以 改 成 :string[] array = Regex.Split(input, @"[;_](?=\d{4}-\d{1,2}-\d{1,2})"); string strContent = "iphone;motorala;LG;nokia;samsung;sony;2009-11-11_2010-12-12"; Regex re = new Regex(@"(?<info>.*;)(?<Date1>(\d+-){2}\d+).*?(?=\d)(?<Date2>(\d+-){2}\d+)"); string string1 = ""; string string2 = ""; string string3 = ""; if (re.IsMatch(strContent)) { Match m = re.Match(strContent); string1 = m.Groups["info"].Value.Trim(); string2 = m.Groups["Date1"].Value.Trim(); string3 = m.Groups["Date2"].Value.Trim(); } Form认证 [新手]帮忙纠正这个涉及到对象的调用的代码 水晶报表图表的变更主体问题 添加Web引用时,出现“处的文档未被识别为已知的文档类型”的错误,怎么解决? .net发布上传到服务器后页面变得断断续续 请教关于textbox自动定位后滚动条问题及选择某一行后该行颜色设置的问题 如何使用js 把一个服务器端的控件 改名字 DataGrid更新数据的问题!100分相送 菜鸟问题 请问asp.net数据显示问题 不是有效的虚拟路径 死人了块 网站优化
string[] arr = s.Split(new char[] { ';' });
string[] date = arr[arr.Length - 1].Split(new char[] { '_' });
Response.Write(date[0] + "||" + date[1]);试试这个,也就是多截一次
"sony;1nokia;"这 样 的 格 式 .空 军 的 正 则 完 全 可 以 用 ..
如 果 有 的 话 ,就 会 把 1nokia也 提 出 来 ..
可 以 改 成 :string[] array = Regex.Split(input, @"[;_](?=\d{4}-\d{1,2}-\d{1,2})");
string strContent = "iphone;motorala;LG;nokia;samsung;sony;2009-11-11_2010-12-12";
Regex re = new Regex(@"(?<info>.*;)(?<Date1>(\d+-){2}\d+).*?(?=\d)(?<Date2>(\d+-){2}\d+)");
string string1 = "";
string string2 = "";
string string3 = "";
if (re.IsMatch(strContent))
{
Match m = re.Match(strContent);
string1 = m.Groups["info"].Value.Trim();
string2 = m.Groups["Date1"].Value.Trim();
string3 = m.Groups["Date2"].Value.Trim();
}