日期:2014-05-18  浏览次数:20783 次

C# 截取字符串 并插入数据库
String s1 = @"车行:粤Y12345丰田GTM72140GB轿车,13625874563,出险时间2010-12-23 13:00:00,客户林先生,出险原因碰撞,出险地点福田区滨河路泰然百安居,【深圳人保】";
String s2 = @"([\u4e00-\u9fa5]+:[\u4e00-\u9fa5]{1}[A-Z0-9-]+)([\u4e00-\u9fa5]+[A-Z0-9-]+[\u4e00-\u9fa5]+)([,]{1}\d+[,{1}])([\u4e00-\u9fa5]+[\d-]+\s\d+[:]\d+[:]\d+[,])([\u4e00-\u9fa5]+[,]+)([\u4e00-\u9fa5\s,:.]+)([【]{1}[\u4e00-\u9fa5]+[】]{1})";
  Match m = Regex.Match(s1,s2);
  for (int i = 1; i <= m.Groups.Count; i++)
  {
  Response.Write(m.Groups[i].Value + "<br/>");
  }

车行:粤Y12345
丰田GTM72140GB轿车
,13625874563,
出险时间2010-12-23 13:00:00,
客户林先生,
出险原因碰撞,出险地点福田区滨河路泰然百安居,
【深圳人保】


能不能去掉 “,” 逗号 在怎么插入数据库呀 一行数据对应一个字段



------解决方案--------------------
C# code

string s1 = @"车行:粤Y12345丰田GTM72140GB轿车,13625874563,出险时间2010-12-23 13:00:00,客户林先生,出险原因碰撞,出险地点福田区滨河路泰然百安居,【深圳人保】";
String s2 = @"([\u4e00-\u9fa5]+:[\u4e00-\u9fa5][A-Z0-9-]+)([\u4e00-\u9fa5]+[A-Z0-9-]+[\u4e00-\u9fa5]+),?(\d+),?([\u4e00-\u9fa5]+[\d-]+\s\d+[:]\d+[:]\d+),?([\u4e00-\u9fa5]+),?([\u4e00-\u9fa5\s,:.]+)([【]{1}[\u4e00-\u9fa5]+[】]{1})";
  Match m = Regex.Match(s1,s2);
  for (int i = 1; i <= m.Groups.Count; i++)
  {
  Console.WriteLine(m.Groups[i].Value.TrimEnd(',') );
  }

------解决方案--------------------
String s1 = @"车行:粤Y12345丰田GTM72140GB轿车,13625874563,出险时间2010-12-23 13:00:00,客户林先生,出险原因碰撞,出险地点福田区滨河路泰然百安居,【深圳人保】";
String s2 = @"([\u4e00-\u9fa5]+:[\u4e00-\u9fa5]{1}[A-Z0-9-]+)([\u4e00-\u9fa5]+[A- Z0-9-]+[\u4e00-\u9fa5]+)([,]{1}\d+[,{1}])([\u4e00-\u9fa5]+[\d-]+\s\d+[:] \d+[:]\d+[,])([\u4e00-\u9fa5]+[,]+)([\u4e00-\u9fa5\s,:.]+)([【]{1} [\u4e00-\u9fa5]+[】]{1})";
Match m = Regex.Match(s1,s2);
for (int i = 1; i <= m.Groups.Count; i++)
{
Response.Write(m.Groups[i].Value.Replace(",","") + "<br/>");
}