开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜