Adding a newline into a string in C#

balaweblog picture balaweblog · Oct 22, 2008 · Viewed 943.1k times · Source

I have a string.

string strToProcess = "fkdfdsfdflkdkfk@dfsdfjk72388389@kdkfkdfkkl@jkdjkfjd@jjjk@";

I need to add a newline after every occurence of "@" symbol in the string.

My Output should be like this

fkdfdsfdflkdkfk@
dfsdfjk72388389@
kdkfkdfkkl@
jkdjkfjd@
jjjk@

Answer

Christian C. Salvadó picture Christian C. Salvadó · Oct 22, 2008

Use Environment.NewLine whenever you want in any string. An example:

string text = "fkdfdsfdflkdkfk@dfsdfjk72388389@kdkfkdfkkl@jkdjkfjd@jjjk@";

text = text.Replace("@", "@" + System.Environment.NewLine);