Think about what you need to do in four cases: of course you may choose not to handle certain cases
1. the index is to a white-space character.
2. the index is to a non-white-space character where the next character is a white-space character.
3. the index is to a non-white-space character where the previous character is a white-space character.
4. the index is to a white-space character with other white-space characters before it, or after it, or has white-space before and after it.
some issues you may need to address:
1. trimming extra white-space ... at the end of the first line, or the beginning of the second line ... after the insertion.
2. in .NET C# the line delimiter "Environment.NewLine" is composed of two characters.
3. error-handling, validation of input parameter values
Here is some code to help you get started with the first, simple, case:
static string defaultNewLine = Environment.NewLine;
public static string InsertNewline(string str, int ndx, string nlstr = "")
{
if (nlstr == "") nlstr = defaultNewLine;
if (char.IsWhiteSpace(str[ndx]))
{
return str.Insert(ndx, nlstr);
}
for (int i = ndx + 2; i < str.Length; i++)
{
ndx = i;
}
return "";
}