Objective-c 中向字符串添加反斜杠
我遇到的问题与此处的问题相同。
我什至想编码与他相同的信息(这是asp.net的日期/时间)...
每当我尝试添加反斜杠时,我都会得到两个反斜杠,因为我使用了\。
上面线程中的每个人都声称这是 NSLog 的问题,并且 NSString 确实将 \\
视为 \
。我通过使用数据包嗅探器检查我发送到网络服务器的数据包进一步检查了这一点,我可以确认它正在传输双反斜杠而不是单个反斜杠。
有谁知道如何向 NSString 添加反斜杠?
I have a problem identical to this problem here.
I even want to encode the same infromation as him (it's a date/time for asp.net)...
When ever I try to add a backslash i get two backslashes since I used \.
Everyone in the thread above has claimed that this is a problem with NSLog and that NSString does treat \\
as a \
. I have checked this further by using a packet sniffer to examine the packets I'm sending to the webserver and I can confirm that it is transmitting a double backslash instead of a single backslash.
Does anyone know how to add a backslash to a NSString?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
字符串和 NSLog 对我来说工作得很好:
我错过了什么?
The strings and NSLog are working fine for me:
What am I missing?
试试这个:
我遇到了同样的问题,结果发现我的 JSON 解析器用“\\\\”替换了所有出现的“\\”,所以当我 NSLogged 我的原始代码如下:
这是我得到了什么:
但是,字符串本身包含四个反斜杠(但 NSLog 仅打印其中 2 个)。
这对我有帮助:
结果:
Try this:
I had the same problem, turned out that my JSON Parser replaced all occurrances of "\\" with "\\\\", so when I NSLogged my original code like this:
This is what I got:
However, the string itself contained FOUR backslashes (but only 2 of them are printed by NSLog).
This is what helped me:
The result: