Created
May 26, 2016 20:02
-
-
Save refactorsaurusrex/ddb065269f33d1cd5c4b96d9779f8338 to your computer and use it in GitHub Desktop.
A better way to add line endings at specific positions in a long text string.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var text = "A long string...."; | |
var words = text.Split(' '); | |
var allLines = words.Skip(1).Aggregate(words.Take(1).ToList(), (lines, word) => | |
{ | |
if (lines.Last().Length + word.Length >= 80) | |
lines.Add(word); | |
else | |
lines[lines.Count - 1] += " " + word; | |
return lines; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment