I would like to make a function that break lines from a string.
eg.: "1. " -> "\n1. "
so i could write a code like this
string Input = "1. First option";
Input += "2. Second option";
Input += "3. Third option";
Output = WriteMenu(Input);
and get a string like this
"1. First option
\n2. Second option
\n3. Third option"
The pattern will always be [number][dot][whitespace]. It's not a problem if the first option came with new line.
Give this guy a shot
Input = Regex.Replace(Input, @"(?<!^)(\d+\.)", "\n$1")
Regex rgx = new Regex("(\\d+\\.\\s)");
String replaced = rgx.Replace(Input, Environment.NewLine + "$1");
A bit shorter expression like this would work too:
Regex.Replace(Input, @"(?!^)\d+\.", "\n$0")
1.
- slugster 2012-04-04 00:15