Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Use this code for detect white-space and replace in new line:
C#
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
.
/********************/


I want the output as like..
Hello World...
Fine
Thanku.
Posted
Updated 27-Apr-15 4:37am
v2

/s* stands for: a whitespace, 0 or more repetitions.
This explains (the zero) why you get your result.

Better use:
/s+
 
Share this answer
 
Use this regex pattern:
@"\s{2,}"

which means two or more white space.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900