如何将字符串与符号“ \”进行比较 [英] How to compare a string with symbol '\'
本文介绍了如何将字符串与符号“ \”进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个项目,并且在我的代码中的某个地方,我正在编写:
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.
推荐答案
反斜杠 \
用作转义字符,因此您需要编写:
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.
这篇关于如何将字符串与符号“ \”进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文