Page 1 of 1

Need a working example of "string.equals_ignore_case(st

Posted: Sat Nov 13, 2010 4:33 am
by jerrelDulay
Hiya guys! I'm pulling my hair out over this one. I've tried rearranging and changing this bit of code about three dozen times, changing the check cases, but it never seems to trigger. I need to check a node's name to see if it matches "terrain", but I can't get it to work. I've scoured the internet for an example but couldn't find out.

Code: Select all

core::stringw nodename = node->getName();
	core::stringw nodecheck = "terrain";
	if (nodename.equals_ignore_case(nodecheck) )       //<- this isn't working :/
		terrainNode = (scene::ITerrainSceneNode*) node;
I'd super appreciate a working example of how to properly use "equals_ignore_case". Or if this is even the wrong function to use to check string values, I would also appreciate a point in the right direction.

Thanks guys!
=D

Posted: Sat Nov 13, 2010 6:55 am
by REDDemon
if this is really the code for what you need equals_ignore_case i suggest you to use the operator == instead.

so

Code: Select all

core::stringw A=L"Terrain";
core::stringw B=L"Terrain";

if (A==B)
return true;
with equals_ignore_case

Code: Select all

core::stringw A="TerRAiN";
core::stringw B="TERRAIN";
core::stringw C="terrain";

A.equals_ignore_case (B); //return true
B.equals_ignore_case(C); //return true;
ecc.

the strings are checked and case is ignored. so they are equals also if one has some upper case char and the other one not.

so your code

Code: Select all

core::stringw nodename = node->getName();
   core::stringw nodecheck = "terrain";
   if (nodename.equals_ignore_case(nodecheck) )       //<- this isn't working :/
      terrainNode = (scene::ITerrainSceneNode*) node;

   
is working. probably you need to check "nodename" and probably you will see that its value is not "terrain"(or "TERRAIN" or "terrAIN" ecc).

Posted: Sat Nov 13, 2010 10:53 pm
by jerrelDulay
Thanks a lot, mate! It's workin' now. With your help, I came to the realization I wasn't putting the value of "name" in the right place in the *.irr scene file I was using. I added the name after the file was created.

Code: Select all

<node type="terrain">

		<attributes>
			<string name="Name" value="terrain" />
The problem was that I was putting the value 'terrain' in the string 'name' spot instead of the 'value' position. Cheers mate! Now all that's left is to buy my tizanidine medication online - no prescription.