Suppose I have a string with the text: \"THIS IS A TEST\". How would I split it every n characters? So if n was 10, then it would display:
\"THIS IS A \"
\"T
Let's borrow an implementation from my answer on code review. This inserts a line break every n characters:
public static string SpliceText(string text, int lineLength) {
return Regex.Replace(text, "(.{" + lineLength + "})", "$1" + Environment.NewLine);
}
Edit:
To return an array of strings instead:
public static string[] SpliceText(string text, int lineLength) {
return Regex.Matches(text, ".{1," + lineLength + "}").Cast().Select(m => m.Value).ToArray();
}