i have this text:"i like stackoverflow", and want this result with regexp (separated with \n):
i
l
i
k
e
s
....
how i can do that with c#?
You don't need a regex for this, you can just do this:
string input = "i like stackoverflow";
string result = string.Join("\n", input.Replace(" ", "").ToCharArray());
This code does the following:
input.Replace(" ", "")).ToCharArray()).string.Join("\n", ...))Regular expressions are incredibly useful when their use is warranted. When it's not, though, keep this jwz quote in mind:
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
I'm really not sure regex is ideal for this (see Donut's answer), but if you really want one...
Regex.Replace("i like stackoverflow", "([^\\s]\\s?)", "$1\n");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With