How to compare a string with symbol '\'

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 02:59:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!