I have textbox which should be used to send formatted text to remote application, and I should format it so it breaks on closest space to 30th character (spaces included) and that space on which line is broken, should be deleted, so it isn’t taken to next row. And of course, it should do it to the end of the text (break, start counting again, break, and so on).
-Other Thing is that characters for formatting text should be excluded from counting.
I have solution, found here on SO, but it works for one row.
string sTemp = textBox1.Text.Substring(0, 30);
sTemp = sTemp.Replace(" @A ", "");
sTemp = sTemp.Replace("@A ", "");
sTemp = sTemp.Replace(" @A", "");
sTemp = sTemp.Replace("@A", "");
sTemp = sTemp.Replace(" @B ", "");
sTemp = sTemp.Replace("@B ", "");
sTemp = sTemp.Replace(" @B", "");
sTemp = sTemp.Replace("@B", "");
int numberOfLeak = 30 - sTemp.Length;
var x = 30 + numberOfLeak;
if (textBox1.Text.Length > x)
{
textBox1.Text = textBox1.Text.Insert(x, Environment.NewLine);
}
Can someone please help to make this work for many lines, until the end of text?
Thanks in advance.
An
<input type="text" />(which is default markup generated for anasp:textbox) is supposed to have only one line of text.You should use a textarea instead by setting the TextMode property to Multiline:
Edit:
I’ve come with this simple piece of code. It replaces the closest white space to the
rangeposition (so after or before this point):It returns me the following piece of string: