using c# 4.8 I get and exception when combining the string Substring and Remove methods.
this is the string I'm working with inside the square brackets (the value of the variable x):
[ "x": -89.05621501099995,]
and this is my code:
string test = x.Substring(13).Remove(x.Length-1);
I'm using x.Substring(13) to remove all text the the left of the minus sign.
and I'm using .Remove(x.Length-1) to remove the trailing comma.
But the remove method gives me this exception:
'x.Substring(13).Remove(x.Length-2)' threw an exception of type 'System.ArgumentOutOfRangeException'
Note: this works if I split this into 2 lines of code and add a new variable like this:
string strX = x.Substring(13);
strX = strX.Remove(strX.Length - 2);
but I have to apply the same process to a bunch of variables all in a loop with 100s of 1000s of loops server side, so I'm trying to optimize this.
Any ideas on the best way to approach this?
Thanks.