String operator
-
On 14/06/2013 at 07:17, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R14
Platform: Windows ;
Language(s) : C++ ;---------
Hi Folks,I'm trying to compare two string values and return a LONG value based on whether the string's are the same or not. Example below:
std::vector< String > MyVectorStrings; // 6 vectors, 1-5 with strings (0 is empty) MyVectorStrings[1] = "StringOne"; etc LONG DataChecker(String MyString) { LONG Value = 0; if(MyString.operator==("StringOne")) { Value= 1; return Value; } if(MyString.operator==("StringTwo")) { Value = 2; return Value; } return Value; // should return 0 if nothing above is true } Bool MyFunction(void) { LONG value = 0; for(int i = 1; i <= 5;) // vector[0] is empty, start at 1 { value = DataChecker(MyVectorStrings[i]); GePrint(LongToString(value)); // everything bar the first vector returns 0. This is not correct. i++; } return TRUE; }
The above is the custom function I run from inside a loop, with a mock example of the loop below it. The string is taken from a vector of String's, one at a time through the loop using the 'i' value.
I've tried with the string operator "if's" inside the loop too, but it didn't work either. I simply cannot get anything passed the first "if" statement to return the correct value. But I know the strings are correct, I've printed them out - many times over.
Is there something buggy with this operator? The MyString.compare() does the same thing too.
WP.
-
On 14/06/2013 at 08:03, xxxxxxxx wrote:
use stringA.Compare(stringB) to compare two strings
-
On 14/06/2013 at 10:13, xxxxxxxx wrote:
Hi Katachi,
I should have mentioned I've been through the Compare() route as well. I thought I had that in my first post, apologies. Variants I've tried:
LONG Zero = 0; if(MyString.Compare(String("StringTwo"))==Zero) // with and without ==Zero { //... }
WP.
Edit: I've just printed the long values coming from the Compare, and there maybe some strange numbers printing... will update again shortly.
-
On 14/06/2013 at 10:16, xxxxxxxx wrote:
And what is the problem with it exactly? It will return 0 if they are exactly the same (case-sensitive, alphanumerically). Works just fine here.
-
On 14/06/2013 at 10:34, xxxxxxxx wrote:
Yeah - and zero was what I wanted in the compare case, but I've just found I'm only getting back zero (as in "0") from the first one. I'm investigating the other values now, and why they're not 0..
WP.
-
On 14/06/2013 at 11:57, xxxxxxxx wrote:
I knew I smelt a rat... the numbers were definitely not right after the first if statement. The issue though was the vector strings after the first one were housing a space or line break that wasn't meant to be there. For Some reason it wouldn't print that in the console either, which is why I hadn't noticed it before.
Thanks Katachi,
WP.