Here are some hints.
Look at the documentation for the StringBuilder class. Notice that you
can create an empty StringBuilder and append things to it, then convert
the finished product to a string using the ToString() method of your
StringBuilder object.
If you really want every exactly 50 characters, just check into the
Substring method of String. If you need to do a more sophisticated
determination of where to break the string, write a method that takes a
string and an index and returns the length of the substring to break
off. For example, if you wanted to break the string at a blank space,
but at most 50 characters, a method like this might be useful:
private static int LineLength(string line, int startIndex)
{
int endIndex = startIndex + 50;
if (endIndex >= line.Length)
{
endIndex = line.Length - 1;
}
while (endIndex > startIndex && !Char.IsWhiteSpace(line[endIndex]))
{
endIndex--;
}
if (endIndex <= startIndex)
{
// return 50 or the remainder of the string, whichever is less
return Math.Min(50, line.Length - startIndex);
}
else
{
return endIndex - startIndex;
}
}
The part where you break up the string and reassemble it with newlines
would look like this:
int startIndex = 0;
StringBuilder sb = new StringBuilder();
while (startIndex < line.Length)
{
if (sb.Length > 0)
{
... append a newline to the StringBuilder ...
}
... append a chunk of the string "line" to the StringBuilder
... update "startIndex" to be the next place in the string "line"
to start
}
.... convert the StringBuilder to a string
and you're done!