>as I understand this does not have the same function as .rfind.
Yes, yes it does.
>int index = str.rfind(" ", 3); //index should return 1
Correct.
>index = tot->LastIndexOf(" "); //Returns 4
Correct, but this isn't an equivalent call to the rfind call you compared with. If you use the overload of LastIndexOf that takes a starting index, and make that starting index 3, you'll find that it returns 1 as well:
#include <iostream>
#include <string>
using namespace System;
int main()
{
std::string s1 = "1 23 56";
String^ s2 = "1 23 56";
Console::WriteLine( s1.rfind ( " ", 3 ) );
Console::WriteLine( s2->LastIndexOf ( " ", 3 ) );
}
>If you will use LastIndexOf you are looking from the beginning of the string and not backwards.
I fail to see how you could think that when the documentation explicitly says this (for String::LastIndexOf(String)):
The search begins at the last character position of this instance and proceeds backward toward the beginning until either value is found or the first character position has been examined.
And this (for String::LastIndexOf(String, Int32)):
The search begins at the startIndex character position of this instance and proceeds backward toward the beginning until either value is found or the first character position has been examined. For example, if startIndex is Length - 1, the method searches every character from the last character in the string to the beginning.