开发者

Ask: Replace multiple new line into single new line or br

I have problem with replace character.

If I have one textbox, and I write into textbox with many new line.

and the results I wanted a lot of new lines replaced with one or two new lines such as comments in the facebook.

I'l try this code :

litText.Text = System.Text.RegularExpressions.Regex.Replace(Text1.Text, "[\\r\\n]+", "<br /><br />", System.Text.RegularExpressions.RegexOptions.Multiline); 

this works if I press a lot of button enter,but this isn't works if I press button enter once then displays new line twice开发者_如何学编程. I want if I press once or two button enter, fixed display once or two new line. except three times or more than two.

please your assistance and your opinions.

Thank you


You want to duplicate the entire \r\n multiple times, as opposed to just duplicating one of them like in your example. Also you should use @"..." for this.

litText.Text = System.Text.RegularExpressions.Regex.Replace(
    Text1.Text, @"(\r\n|\r|\n)+", "<br>", 
    System.Text.RegularExpressions.RegexOptions.Multiline);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜