xcode nsstring stringByReplacingOccurrencesOfString 挫折?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8378505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
nsstring stringByReplacingOccurrencesOfString frustration?
提问by BlockReader
I am trying to replace/remove this:
我正在尝试替换/删除这个:
[\"
[\"
from string bump3
从字符串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:@""];
所以我使用 NSString *bump5 = [bump3 stringByReplacingOccurrencesOfString:@"[\\"" withString:@""];
回答by jbat100
You should escape both \
and "
你应该同时逃避\
和"
NSString *bump5 = [bump3 stringByReplacingOccurrencesOfString:@"[\\"" withString:@""];
回答by oscar castellon
Try this to remove a "-" from a string. for example a chain 2773848-2294-2929
试试这个从字符串中删除“-”。例如链 2773848-2294-2929
string = 2773848-2294-2929;
NSString * replace = [string stringByReplacingOccurrencesOfString: @ "-" withString: @ ""];
The result will return the following string: 277384822942929
结果将返回以下字符串:277384822942929