I’ve been trying to remove a substring by a specific length at the beginning or at the end.
Here’s the code I’ve written and not working, though.
this.temp = String.Empty;
foreach (string line in this.txtBox.Lines) {
if (Envir.Operations.Begin == true)
this.temp += line.Substring(Envir.Operations.Length - 1) + Environment.NewLine;
else
this.temp += line.Substring(0, line.Length - Envir.Operations.Length) + Environment.NewLine;
}
Would you be so kind to let me know if you have any idea how to fix this?
Thanks a lot!
Your code looks good, for except it does not check for input string being longer than you the length you need. It may result in out of range exception. Modify your code like this:
}