由网友(陪你闹看你笑)分享简介:看来.NET Regex.Replace方法会自动替换所有匹配的事件。我可以提供一个MatchEvaluator委托,返回匹配字符串的第一个更换后,呈现没有变化,但听起来非常低效的我。什么是停止第一置换术后最有效的方法是什么?解决方案 从MSDN: 替换(字符串,字符串,Int32)将在一个指定的输入字符串,替换字符...
看来.NET Regex.Replace方法会自动替换所有匹配的事件。我可以提供一个MatchEvaluator委托,返回匹配字符串的第一个更换后,呈现没有变化,但听起来非常低效的我。
什么是停止第一置换术后最有效的方法是什么?
解决方案从MSDN:
替换(字符串,字符串,Int32)将
在一个指定的输入字符串,替换字符串指定的最大数量的 与指定的字符串替换常规EX pression模式进行匹配。
这是不是你想要的?
It seems the .NET Regex.Replace method automatically replaces all matching occurrences. I could provide a MatchEvaluator delegate that returns the matched string after the first replacement, rendering no change, but that sounds very inefficient to me.
What is the most efficient way to stop after the first replacement?
解决方案From MSDN:
Replace(String, String, Int32)
Within a specified input string, replaces a specified maximum number of strings that match a regular expression pattern with a specified replacement string.
Isn't this what you want?
相关推荐
最新文章