Case insensitive string comparison

0 favourites
  • 5 posts
From the Asset Store
See how your Logical Resolution looks on different devices
  • Hi!

    Is it possible to compare a string variable in an case insensitive manner?

    Let's say my variable can have "a" or "A". I tried to make an =equal to "a"|"A" expression, but it didn't work.

  • You can use the lowercase() expression to convert your string to lowercase, then compare to a lowercase version.

    "a" Equal lowercase("A") will be true

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks for your reply!

    That doesn't seem to work in my situation, because I'm looping through positions in an array, so there is no place where I can insert the lowercase() expression.

    My code is like this:

    myArray For each X element

    --myArray currentValue ="a"

    I also don't want to permanently manipulate the contents of the array (I need to retain the mixed case letters, just not for the comparison).

    Damn.. this is more difficult than I thought. I wonder why =equal to "a"|"A" is not working.

  • You would have to compare lowercase(myArray.CurrentValue) is equal to lowercase("a").

    As for the equal to "a"|"A", | is a logic operation, it will do "a" OR "A" which returns 0 or 1, so you were actually comparing the value to 0 or 1 (not sure what it should even try to return int hat case)

  • Thank you so much! That worked!

    If someone else with the same problem is reading this, let me point out that to do what Aphrodite suggested, I had to choose "system"-->"compare two values" instead of "compare variable".

    Thanks again!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)