nsstring stringByReplacingOccurrencesOfString 沮丧?

发布于 2024-12-19 14:46:09 字数 411 浏览 4 评论 0原文

我正在尝试替换/删除这个:

[\"

from string Bump3

NSString *bump5 = [bump3 stringByReplacingOccurrencesOfString:@"[\\"" withString:@""];

错误:缺少终止“”字符。

有人可以帮我吗?我的大脑因盯着这个屏幕而焦躁不安。

更新:

偶然发现了这一点并且尝试了一下!

@“\”是一个反斜杠 @“\\”是一个双反斜杠

,所以我用了 NSString *bump5 = [bump3 stringByReplacingOccurrencesOfString:@"[\\"" withString:@""];

I am trying to replace/remove this:

[\"

from string bump3

NSString *bump5 = [bump3 stringByReplacingOccurrencesOfString:@"[\\"" withString:@""];

ERROR: missing terminating "" character.

could someone please help me out? My brain is so fried from staring at this screen..

UPDATE:

Figured it out by chance and tried it out!

@"\" is a single backslash
@"\\" is a double backslash

so I used
NSString *bump5 = [bump3 stringByReplacingOccurrencesOfString:@"[\\"" withString:@""];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

欲拥i 2024-12-26 14:46:09

您应该转义 \"

NSString *bump5 = [bump3 stringByReplacingOccurrencesOfString:@"[\\\"" withString:@""];

You should escape both \ and "

NSString *bump5 = [bump3 stringByReplacingOccurrencesOfString:@"[\\\"" withString:@""];
平生欢 2024-12-26 14:46:09

尝试从字符串中删除“-”。
例如链 2773848-2294-2929

string = 2773848-2294-2929; 
NSString * replace = [string stringByReplacingOccurrencesOfString: @ "-" withString: @ ""];

结果将返回以下字符串:
277384822942929

Try this to remove a "-" from a string.
for example a chain 2773848-2294-2929

string = 2773848-2294-2929; 
NSString * replace = [string stringByReplacingOccurrencesOfString: @ "-" withString: @ ""];

The result will return the following string:
277384822942929

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文