2

我已使用此代码将“\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;
4

2 回答 2

10

试试这个

NSString *s = @"foo/bar:baz.foo";
NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"/:."];
s = [[s componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @""];
NSLog(@"%@", s);
于 2012-04-10T09:45:54.980 回答
5
descString = [descString stringByReplacingOccurrencesOfString:@"\\n" withString:@""];

有关详细信息,请参阅stringByReplacingOccurrencesOfString:withString:方法

希望这对您有所帮助。

更新

斯威夫特 3.0

descString.replacingOccurrences(of: "\\n", with: "");

如果我不拧,它也适用于Swift 4.0

于 2012-04-10T10:04:34.667 回答