Skip to content

Instantly share code, notes, and snippets.

@ichengzi
Created August 16, 2018 07:12
Show Gist options
  • Save ichengzi/1dcab065ea667cd2fba29c6ec2ae5e17 to your computer and use it in GitHub Desktop.
Save ichengzi/1dcab065ea667cd2fba29c6ec2ae5e17 to your computer and use it in GitHub Desktop.
SplitString and InsertNewLine
public static string InsertNewLine(string source, int len = 76)
{
var sb = new StringBuilder(source.Length + (int)(source.Length / len) + 1);
var start = 0;
while ((start + len) < source.Length)
{
sb.Append(source.Substring(start, len));
sb.Append(Environment.NewLine);
start += len;
}
sb.Append(source.Substring(start));
return sb.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment