[SOLVED]How do I compare special characters.

  • I am trying the following which should work. The text box contains a "$" string. I have tried a few other special characters and it also does not work. It works with ordinary characters though.

  • Maybe make a global variable called DollarSign with the text "$", and then use that? So > letterText > Text is DollarSign (Ignore Case)

  • I tried that also and does not work. I did discover that the special characters are recognised as both upper and lower case. Don't know if that means anything though.

  • mattshallow , Your code works fine for me.

    Do you need to check if the text contains "$", or if it exactly is "$"?

    If the text is something like "Price $5" and you need to know if it contains $ symbol, then use this:

    System-> Compare two values -> find(letterText.Text, "$")>=0

  • [quote:2nymnz3y]Do you need to check if the text contains "$", or if it exactly is "$"?

    I need to check if the text is "$". To be more precise I need to check if the text is any special character. I was looking a regex but I am not sure which regex will suite my needs.

    So to be clear. I have a piece of text that can hold one special character. I need to do a check to see if that text is one of the special characters so I can add to a variable.

  • I have a bit of a workaround now:

    System->left(letterText.Text, 0) = "$"

    Checks the left most character and I can compare. I'll see if I can get it to check all special chars rather than having to multiple checks for each character.

  • Then the screenshot that you posted should work! I rested it and it works for me.

    Could your text contains something else besides the $? Maybe some invisible character - a line break or a space. Try this condition:

    trim(letterText.Text) = "$"

  • If it does I will hit myself! I'll check now....

  • No there is nothing else there. I have a text file of letters with special chars and using AJAX to read them in. I am then populating an array. The letter comparison check works fine but the special chars do not. The original piece of code I have in screen shot still does not work.

    Maybe when the char is converted from .txt the formatting for special chars is altered. Or possibly when read into the array but I can see the values in the debugger. Below is the code reading file and placing in array. I am actually randomly selecting letters from array to place individually on object.

  • Are there line breaks or spaces between each token in the file? I had a similar issue and turned out that linebreaks are not shown in debug mode, so it was hard to find...

    Just to be sure, check if len(letterText) returns 1.

    Also try changing encoding of the text file. You can press Save As in Notepad, save with a different encoding method to a folder and then re-import the file to the project.

    If nothing helps, could you share your capx?

  • I'll see if I can get it to check all special chars rather than having to multiple checks for each character.

    simple regex would work. For example, "^[!@#$%?&*()]$" would check if the character is one of those inside the brackets. You can add more symbols as you will. If you want to check for "]", add "\]" inside the brackets, and if you want to check for "\", add "\\".

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • [quote:qr1741gp]Are there line breaks or spaces between each token in the file

    Nope. The condition in original screenshot works with other letters in the file. Just not with special chars.

    I tried changing format of file and used trim() to make sure no extra chars in the text but still no luck. I think regex is the way to go if I figure that out but this issue might pop up again so want to resolve that first.

    Attach is the capx.

    https://drive.google.com/open?id=1ZSuWmbdBYQGwgfM5Nbl9g4ioLBIBJ8nl

    Thanks again for your help!

  • [quote:20ol6kky]A simple regex would work. For example, "^[!@#$%?&*()]$"

    RegexSearch does the job. It is now working

    RegexSearch(letterText.Text, "^[!@#$%?&*()]$", "i")

    I was not too familiar with regex but since you gave me the format for it that made testing much easier. I need to read up more on regex.

    I appreciate all the help guys!

  • I spoke too soon. regex search seems to not filter the strings at all. I wonder do you know the particular regex function I should be using for this check?

  • OK, this works.

    RegexSearch(letterText.Text, "", "i")

    removing ^ and $ before and after square brackets while also having the correct boolean check.

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