在此代码中帮助将white-space替换为换行符? [英] Help in this code for replace white-space into newline?
本文介绍了在此代码中帮助将white-space替换为换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用此代码检测空格并替换为新行:
I Use this code for detect white-space and replace in new line:
string text = "Hello World... Fine Thanku.";
Regex rx = new Regex(@"\s*");
string outstr = rx.Replace(text, "\n").Trim();
TextBox2.Text = outstr;
输出有这种类型..
output come in this type..
/***********Output***************/
H
e
l
l
o
W
o
r
l
d
.
.
.
F
i
n
e
T
h
a
n
k
u
.
/********************/
我希望输出像..
Hello World ...
罚款
感谢。
I want the output as like..
Hello World...
Fine
Thanku.
推荐答案
/ s *
代表:空格,0或更多重复。
这解释了(零)为什么你得到你的结果。
更好用:
/ s +
/s*
stands for: a whitespace, 0 or more repetitions.
This explains (the zero) why you get your result.
Better use:
/s+
使用此正则表达式模式:
Use this regex pattern:
@"\s{2,}"
这意味着两个或更多的空格。
which means two or more white space.
这篇关于在此代码中帮助将white-space替换为换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文