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

size=2699309

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

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.

s(0)i(1)z(2)e(3)=(4)2(5)699309

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

commented: Perfect explanation +1

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

Example:

string yourstring = "HELLO";

Console.WriteLine(yourstring.SubString(2))

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=)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.