0

I have a project and somewhere in my code I'm writing this:

else if (character[0] == '\'){

How can I compare my character with this symbol? Every other symbol that I tried to compare like ,, ;, etc. is done and this is the only symbol that I'm getting a wrong message.

2
  • '\\' or '/'? And how are you comparing the characters?
    – Biffen
    Mar 4, 2015 at 9:23
  • sorry i edit my question. i mean '\'
    – athinatha
    Mar 4, 2015 at 9:25

2 Answers 2

6

The backslash \ is used as an escape character, so you would need to write:

else if (character[0] == '\\'){

In this case the backslash is being used to escape itself.

4
  • in my program im getting char by char the code and im trying to find if we have comment. So i want to find * because in my language comments are inside this *.....*\. So i want firstly to find \ then * etc but i cant.
    – athinatha
    Mar 4, 2015 at 9:30
  • 1
    How does this relate to the original question ? If you have a new question then please post it as such.
    – Paul R
    Mar 4, 2015 at 9:31
  • im telling you this because when im going to compare my character with '\' im getting wrong message but now that i used the ascii code 92 i think is true
    – athinatha
    Mar 4, 2015 at 9:37
  • 2
    Why aren't you just using '\\' as described above ? That would be a better solution then using the ASCII code.
    – Paul R
    Mar 4, 2015 at 9:39
2

I'm not clear on what you ask. Do you mean to compare like this:

if (character[0] == '\\') { 

or you could do

if (character[0] == 92) { // ASCII-Code
1
  • in my program im getting char by char the code and im trying to find if we have comment. So i want to find * because in my language comments are inside this *.....*\. So i want firstly to find \ then * etc but i cant.
    – athinatha
    Mar 4, 2015 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.