问题
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.
回答1:
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.
回答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
来源:https://stackoverflow.com/questions/28850657/how-to-compare-a-string-with-symbol