0

I have this code:

        var text = "ß042´ßzpüwhü90hu54/()=?*/()=?*";
        var symboles = "!§$%&/()=?*<;:-<,.-#+|~}][{@€";
        var symbolsContained = "", found = false;
        for (var i = 0; i < symboles.length; i++) {
            if (text.indexOf(symboles[i]) != -1) {
                found = true;
                symbolsContained += symboles[i];
            }
        }
        console.log(symbolsContained, symbolsContained.length);

Unfortunately it is not working properly:

  • symboles[1] finds a character that is not in the list ("A" with a ":" above it)
  • The "€" is not processed properly

Using substr() doesn't fix this. I guess it is a subject of character encoding but this is still a mystery for me. Any hint how this can be fixed?

Sempervivum
  • 928
  • 1
  • 9
  • 21
  • Use charcodes maybe? – Manu Masson Jun 05 '16 at 08:32
  • `/()=?* 6` this is the output I'm getting, what are you expecting ? – 11thdimension Jun 05 '16 at 08:34
  • Yes, for these characters it works fine but I used the debugger and found out that symboles[1] finds a character that is not in the list ("A" with a ":" above it) and "€" is not processed properly (script finds three cryptic characters at that position). – Sempervivum Jun 05 '16 at 09:02
  • Possible duplicate of [javascript code to check special characters](http://stackoverflow.com/questions/11896599/javascript-code-to-check-special-characters) – e666 Jun 05 '16 at 09:19

1 Answers1

0

Regarding the Euro sign I found the solution here: https://www.experts-exchange.com/questions/21092349/Euro-character-in-javascript.html

        var symboles = "!§$%&/()=?*<;:-<,.-#+|~}][{@\u20AC";

Remains the cryptic character at symboles[1] which also appears in the result. In 11dimension's environment apparently this is not the case. I have Windows 7 and Opera.

Sempervivum
  • 928
  • 1
  • 9
  • 21