What does the substring function do? The answer i found online doesn't seem to be accurate. I thought that it reads the (#) index and everything after, but I guess that is wrong. The other functions that look wierd are already part of a class, i am just confused on how the substring function works, trying to decipher over a thousand lines of code and don't understand the small things in C# that aren't in C++. Ty for the help

Here is my example


if (line.StartsWith("size="))
     patch.FileSize = int.Parse(line.SubString(5));

It does exactly what you think it does. You don't say what problem you are having so it's hard to figure out what it is you think it is doing. Your code there works fine.

the substring is an instance method of type string that takes an indexed start int and returns that character in the string to the end.

so, if string line = "size=2699309";
then line.SubString(5) would count to the index of 5 or the the 6th character in the string and return that character til the end of the string.


since the 2 in 2699309 is in the Index position of 5. the 2 til the end of the string is return as a new string 2699309

Edited 5 Years Ago by Diamonddrake: n/a

Perfect explanation

.SubString will return the rest of the string from the element you specify onwards...


string yourstring = "HELLO";


in this case the output on the console would be LLO...

Hope that makes sense?

Ty all for answer

Ty DiamondDrake for the detailed answer, i forgot to count the other pieces (size=)

This question has already been answered. Start a new discussion instead.