开发者

Regex.Replace: replace only first one found [duplicate]

开发者 https://www.devze.com 2023-03-13 15:40 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: How to Regex search/replace only first occurrence in a string in .NET?
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

How to Regex search/replace only first occurrence in a string in .NET?

How do I make Regex.Replace replace only 开发者_如何学JAVAthe first found pattern?


What about Regex.Replace ( String, String, Int32 ) (MSDN) ?

An example:

Regex rgx = new Regex(pattern);
string result = rgx.Replace(str, replacement, 1); // The 1 makes the difference


http://msdn.microsoft.com/en-us/library/haekbhys.aspx

you can use Regex.Replace(input, replacement, count);

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号