Reputation: 21990
How can I stretch some string element _text
from
A
B
C
to
A
B
C
?
Actually, I have some text getting from DB
_text = this.NormalizeString(DinamicLibrary.LoadText(DinamicLibrary.Path[(int)_category] + _textdllName, this.TextNumber));
What should I do with this query or with _text
later to get what I want?
I understand that I should change \n
to \n\n
but dunno how.
Upvotes: 4
Views: 4922
Reputation: 56222
var result = s.Replace(Environment.NewLine, Environment.NewLine + Environment.NewLine);
Upvotes: 12
Reputation: 56222
To match from 3rd \r\n
you can use regex: (?s)(?<=(?:\r\n[^\r\n]*){2})\r\n
, e.g.:
var s = @"A
B
C
D
E
F";
var result = Regex.Replace(s, @"(?s)(?<=(?:\r\n[^\r\n]*){2})\r\n", Environment.NewLine +
Environment.NewLine);
Output:
A
B
C
D
E
F
Upvotes: 1
Reputation: 452
typically a line break is a combination of \r and \n, which equals to Environment.NewLine("\r\n"). But a single \n can also perform a line break. Both are good, just use replace method to add another line breaker.
Upvotes: 0
Reputation: 11
You can use Environment.NewLine and String.Replace()
_text.Replace("\n", Environment.NewLine + Environment.NewLine);
Upvotes: 0
Reputation: 60556
string newString = oldString.Replace(Environment.NewLine, Environment.NewLine + Environment.NewLine);
Upvotes: 1
Reputation: 26446
You can duplicate newlines, using _text.Replace("\n", "\n\n");
. You actually provided that answer, I just knew the name of the method to call :)
Upvotes: 0