在Objective-c中将反斜杠添加到String [英] Add backslash to String in Objective-c

查看:172
本文介绍了在Objective-c中将反斜杠添加到String的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与此问题相同的问题此处



我甚至想编码与他相同的信息(这是asp.net的日期/时间)...



当我尝试添加反斜杠时,我得到两个反斜杠,因为我使用\。



上面的线程中的每个人声称这是NSLog的一个问题, NSString将 \\ 作为 \ 。我已经通过使用数据包嗅探器检查我发送到Web服务器的数据包,并进一步检查了这一点,我可以确认它传输双反斜杠而不是单个反斜杠。



有没有人知道如何向NSString添加反斜杠?

解决方案

字符串和NSLog对我来说工作正常:

  NSLog(@\\); //输出是一个反斜杠
NSLog(@\\\\); //输出是两个反斜杠
NSLog(@\\ / Date(100034234)\\ /); //输出是\ / Date(100034234)\ /

我缺少什么? p>

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?

解决方案

The strings and NSLog are working fine for me:

NSLog(@"\\"); // output is one backslash
NSLog(@"\\\\"); // output is two backslashes
NSLog(@"\\/Date(100034234)\\/"); // output is \/Date(100034234)\/

What am I missing?

这篇关于在Objective-c中将反斜杠添加到String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆