Use a second variable:
foreach (string s in Regex.Split(replicFile, Environment.NewLine))
{
string spline = s;
Label9.Text = spline;
this.Refresh();
while (spline.EndsWith(('\n').ToString()) || spline.EndsWith(('\r').ToString()))
{
spline = spline.Substring(0, spline.Length - 1);
}
while (spline.StartsWith(('\n').ToString()) || spline.StartsWith(('\r').ToString()))
{
spline = spline.Substring(1, spline.Length - 1);
}
NB: You can replace both of those
while
loops with a single call to
String.Trim[
^]:
foreach (string s in Regex.Split(replicFile, Environment.NewLine))
{
string spline = s;
Label9.Text = spline;
this.Refresh();
spline = spline.Trim(new[] { '\r', '\n' });