您的位置:首页 > 其它

正则表达式替换指定位置的字符串

2017-07-17 17:51 1316 查看
public string GetRePlaceStr(string str, string pattern, string newstr, int index=1)
{
Regex reg = new Regex(pattern);
//查询匹配数量
var t = reg.Matches(str);
return reg.Replace(str, newstr,1,t[index-1].Index);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: