J
jwgoerlich
Hello group,
What is the fastest way to remove line feeds from the end of a string?
RegEx was too slow. I am using a for loop (code below), but that seems
too cumbersome.
Any suggestions appreciated.
J Wolfgang Goerlich
string logText = txtOutput.Text;
string s10 = Convert.ToChar(10).ToString();
string s13 = Convert.ToChar(13).ToString();
for (int i = logText.Length - 1; i > 0; i--)
{
string s = logText.Substring(i, 1);
if (s == s10 | s == s13)
{
logText = logText.Remove(i);
i--;
}
else
{
break;
}
}
txtOutput.Text = logText;
What is the fastest way to remove line feeds from the end of a string?
RegEx was too slow. I am using a for loop (code below), but that seems
too cumbersome.
Any suggestions appreciated.
J Wolfgang Goerlich
string logText = txtOutput.Text;
string s10 = Convert.ToChar(10).ToString();
string s13 = Convert.ToChar(13).ToString();
for (int i = logText.Length - 1; i > 0; i--)
{
string s = logText.Substring(i, 1);
if (s == s10 | s == s13)
{
logText = logText.Remove(i);
i--;
}
else
{
break;
}
}
txtOutput.Text = logText;