It means that the values you are passing to Substring
are not valid for the string they are being called on. For example:
string s = "hello";
string x = s.Substring(0, 1); // <-- This is fine (returns "h")
string y = s.Substring(1, 3); // <-- Also fine (returns "ell")
string z = s.Substring(5, 3); // <-- Throws an exception because 5 is passed
// the end of 's' (which only has 5 characters)
As an aside, I see this a lot:
item.Split(new char[]{' '})
I think people are confused by the signature of the Split
method. The following is sufficient:
item.Split(' ')
solved Using substring in line C# [closed]