One, code.
- (void) Viewdidload {[Super viewdidload];//Additional setup after loading the view, typically from a nib.//Replace carriage return and space NSString *oldstr=@"1 2 4"; NSLog (@"----OLDSTR---%@ ",oldstr); // Remove the leading and trailing spaces NSString *newstr= [oldstr stringbytrimmingcharactersinset:[nscharacterset Whitespacecharacterset]; NSLog (@ "---newstr---%@" ,newstr); // Remove the middle space nsstring *newnewstr=[newstr Stringbyreplacingoccurrencesofstring:@ "" withstring:< Span style= "COLOR: #800000" >@ "" "; NSLog (@ "---newnewstr--%@ ",newnewstr);
Two, output.
2015-10-2313:16:50.310 string substitution carriage return and line break [7678:198286]----OLDSTR---1 2 4 2015-10-23 13:< Span style= "COLOR: #800080" >16:50.311 string replace carriage return and line break [7678:< Span style= "COLOR: #800080" >198286]---newstr---1 2 42015-10- 23 13:16:50.311 string replace carriage return and line break [7678:198286]--- Newnewstr--124
"Code note" ios-string replace carriage return and line break