怎样把字符串中不是3位数字的子字符串去掉?(以空格分隔)
如str="123 46789 789"
最后得到newstr="123 789"
谢谢!
如str="123 46789 789"
最后得到newstr="123 789"
谢谢!
解决方案 »
- 服务器问题求解!
- 急!!!!!!找不到可安装的 ISAM
- 100分,在线等,toolbar中的按钮怎么弹出confirm对方框啊?我用Toolbar1.Attributes.Add("onclick","return confirm('确定?');");结果每
- 有关如何动态创建treeview的问题
- 急救:asp与.net,共用session值!
- 请教Char.IsMunber()如何用?
- 转化成PDF
- C#的程序 开发.谁帮我做?我开钱,请人做
- 求助 .net 报表rdlc打印内容换行问题
- 关于Validator控件的一点尝试
- timeout我设置的是60,可是不到5分钟就会自动转到index.aspx页面,请问有什么办法设置啊,急,....在线等...
- 看过Scott Mitchell的ASP.NET2.0数据教程的请问几个问题!
Regex r = new Regex(@" ?\d{4,100} ?");if (r.IsMatch(s))
{
s = r.Replace(s, " ");
Console.WriteLine(s);
}
{
string aaa = Regex.Replace(temp,@"\d+",new MatchEvaluator(CorrectString),RegexOptions.Compiled|RegexOptions.IgnoreCase);
return aaa;
}
private static string CorrectString(Match match)
{
string matchValue = match.Value;
if(matchValue.Length == 3)
matchValue = matchValue;
else
matchValue = null;
return matchValue;
}
Regex r = new Regex(@" ?\d{4,100} ?");if (r.IsMatch(s))
{
s = r.Replace(s, " ");
Console.WriteLine(s);
}
------------------------
这个是错误的,只判断了四个以上的,如果有两个字符就没有替换掉,改一下参数
string content = @"123 46789 112 2345";
string strRegex = "\\b\\S{4,}\\s|\\s\\S{4,}\\b";
strValue = Regex.Replace(content, strRegex, "" , RegexOptions.IgnoreCase);
string content = @"123 1 1 46789 112 2345";
string strRegex = "\\b(\\S{4,}|\\S{2}|\\S{1})\\s|\\s(\\S{4,}|\\S{2}|\\S{1})\\b";
strValue = Regex.Replace(content, strRegex, "" , RegexOptions.IgnoreCase);