I have a string like this: 2899 8761 014 00:00:00 06/03/13 09:35 G918884770707
. I have to take the substring G918884770707
from this given string. I know the start of the substring so I'm taking the end of the substring as the length of the whole string like this:
No = line.Substring(Start,End);
Here the value of Start is 39
and the length of the main string is 52
so this is the value for End.
This causes the error:
Index and length must refer to a location within the string error in substring
How do I resolve this?
You've misunderstood the parameters to
Substring
- they aren't start and end (as they are in Java), they're start and length.So you want:
From the docs:
Always, always read the documentation - particularly if you're getting an exception that you don't understand.