Remove string iOS development of both spaces newline

(1) The method of removing a string of trailing spaces:

NSString *str = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

 (2) The method of removing the wrapping string inclusive of:

NSString *str = [str stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];

(3) The method of removing a string of leading and trailing spaces and line:

NSString *str = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

(4) methods to replace all the spaces within the string:

NSString *str = [str stringByReplacingOccurrencesOfString:@" " withString:@""];

(5) a method to replace all the spaces within the string:

NSString *str = [str stringByReplacingOccurrencesOfString:@"\n" withString:@""];

Guess you like

Origin www.cnblogs.com/hecanlin/p/12165846.html