C# How to replace spaces with new lines [closed]

Use:

myString = String.Join(Environment.NewLine, 
                myString.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));

This will split the string based on space and then join them using Environment.NewLine. So in case of multiple spaces only one new line will appear.

Leave a Comment