- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
NSString *URLString = [[url absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSArray *temp = [URLString componentsSeparatedByString:@"\r\n"];
return YES;}
虽然预览显示,但不会分割字符串 仍然在字符串中。 有什么建议吗?
输入 URL 示例 - myapp://bla 布拉
这是替换 % esc 并用 ' 分割后的字符串 ':
这是替换 % esc 之前的 url:
我怀疑替换百分比转义必须对其做一些事情。
根据 Eduardo 但更接近您的代码,以下内容:
NSString *URLString = @"myapp://bla\r\nbla";
NSArray *temp = [URLString componentsSeparatedByString:@"\r\n"];
NSLog(@"%@", temp);
输出:
2014-03-20 12:05:17.247 Untitled 3[437:507] (
"myapp://bla",
bla
)
您传入的字符串是否可能包含文字的四字符序列 ,它会写成
@"\\r\\n"
而不是两个控制代码的序列,
?
尝试以下方法
NSArray *temp = [URLString componentsSeparatedByString:@"\\r\\n"];
您的初始 URLString 不能包含 CR LF。它只包含两个符号文字 ' ' 和 ' '
是否显示“ “在预览中?这有效:
NSLog(@"%@", [@"abc\r\ndef" componentsSeparatedByString:@"\r\n"]);
如果您的代码不起作用,您确定您的字符串不包含“\r\n”而不是“ “?
编辑:所以“逃脱”我的双斜杠