如何从字符串中删除换行符?

jro*_*yce 1 string objective-c ios

我需要从字符串中删除任何新行字符.我尝试了下面的stringByReplacingOccurencesOfString方法.在Objective C中执行此操作的正确方法是什么?

[textLine stringByReplacingOccurrencesOfString:@"\n" withString:@""];
Run Code Online (Sandbox Code Playgroud)

Tom*_*voy 5

NSString *textWithNewLinesRemoved = [textLine stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
Run Code Online (Sandbox Code Playgroud)