Jump to content
  • Advertisement
Sign in to follow this  
johnboy007

string compare or not to string compare?

This topic is 2718 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys just wondering what to use instead of comparing strings, i have an array containing the names of objects that i need to compare against object names but i know this can be expensive, is there any other way? btw i'm using javascript

Share this post


Link to post
Share on other sites
Advertisement
can you enumerate it ?
in C++ and C# (VB.net and such do it as well i think)

enum ENUMERATE
{
enum1,
enum2,
enum3
//etc
};

// just coneptual code
class whaterver
{
ENUMERATE e = ENUMERATE.enum1;
if(e == ENUMERATE.enum2)
{
}
}

Share this post


Link to post
Share on other sites
Why enumeration?

If he want's a unique identifier per object I don't see the reason why he's not using integer as identifier.

Share this post


Link to post
Share on other sites
Try it first and see if it's slow for your use case; it may not be in which case you don't need to do anything.

Share this post


Link to post
Share on other sites

Why enumeration?

If he want's a unique identifier per object I don't see the reason why he's not using integer as identifier.



Readability, typically.

Share this post


Link to post
Share on other sites

Readability, typically.




We are talking about UNIQUE identifiers!
Every object created has a different identifier.

How do you want to realize that with enums?


Object *o1 = new Object();
Object *o2 = new Object();
Object *o3 = new Object();

std::cout << o1->identifier; // 1
std::cout << o2->identifier; // 2
std::cout << o3->identifier; // 3

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!