我已经使用此代码将“\ n”替换为“”,但它无效。
我该怎么做?
NSString *descString = [values objectForKey:@"description"];
descString = [descString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
NSLog(@"Description String ---->>> %@",descString);
catlog.description = descString;
[webview loadHTMLString:catlog.description baseURL:nil];
webview.opaque = NO;
descString = [descString stringByReplacingOccurrencesOfString:@"\\n" withString:@""];
有关更多信息,请参阅stringByReplacingOccurrencesOfString:withString:方法
希望这对你有所帮助。
UPDATE
Swift 3.0
descString.replacingOccurrences(of: "\\n", with: "");
如果我没有拧它,它也适用于Swift 4.0
试试这个
NSString *s = @"foo/bar:baz.foo";
NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"/:."];
s = [[s componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @""];
NSLog(@"%@", s);