$string.Substring Index/Length exception


I’m doing the following to try and get the last character from the string (in this case, “0”).

But I’m getting this Substring-related exception:

I understand its meaning, but I’m not sure why I’m getting given the index and length are correct.

Even attempting to hard code it throws the same exception:

Is there something I’m missing?


Your first argument is that starting position in the string, and the second is the length of the substring, starting at that position. The expression for the 2 characters at positions 68 and 69 would be:


$string.Substring Index/Length exception by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply