Posted: Fri Jun 30, 2006 10:20 am Post subject: (No subject)
cool dude,
wtd is trying to nudge you in the right direction. Why say you understand substring when clearly you don't. No need to get defensive and talk about the other languages you know. Just go back and look at the API. No big deal.
Sponsor Sponsor
r.3volved
Posted: Fri Jun 30, 2006 10:22 am Post subject: (No subject)
There's no difference to the for loops. They both do the same thing, but think of it as grammar in english...
You can say:
"How y'all doing today?"
"How is everyone today?"
They are both understandable and lead to the same conclusion but the second is grammatically correct.
You want to go from first character to the last, so the first character is at character array [0] but .length() counts the first character as 1, not 0.
Incrementing by 1 on whole numbers, you know that .length() will be one more than the character array index and the != just avoids off-by-one errors in most cases. ++i and i++ are NOT the same thing. In this case there is no difference, but they both handle the stack differently.
ex.
int i = 1;
int x = 5;
x += i++; //this will add `i` to `x` and then increment `i`
so after execution, `x` will be 6 and `i` will be 2
x += ++i; //this will increment `i` first and then add `i` to `x`
so after execution, `x` will be 7 and `i` will be 2
This often leads to off-by-one errors also (exploit city )
Always remember that the name "C++" is WRONG...should be "++C" based on proper syntax.
----------------------------
As for the substring, the first parameter is the start character and the second parameter is the finish character, not the length. (you must be a c-coder or varient of). Java just does it differently.
If your compiler has active intellisense, make sure you read it well, as each language has it's own qwirks and differences
Hope this helped
Cheers
Martin
Posted: Fri Jun 30, 2006 11:33 am Post subject: (No subject)
substring( int begin, int end ); is the string from begin to end - 1. (begin inclusive to end exclusive).
ie. to get 'mpsc' out of 'compsci', you want to call substring(2,6);
Looks kind of like a lame way to do it. substring(2,5); seems to me like it would be more intuitive.
wtd
Posted: Fri Jun 30, 2006 11:42 am Post subject: (No subject)
r.3volved wrote:
If your compiler has active intellisense, make sure you read it well, as each language has it's own qwirks and differences
As long as you're offering an explanation, let's make sure you get the details right too.
"Intellisense" and other such systems are not a function of a compiler, but rather an IDE. That IDE may include its own particular compiler, but it doesn't need to, and may instead simply use an entirely independent compiler.