This will remove white space from both ends of a string:
NSString *newString = [oldString stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet]];
The whitespaceCharacterSet consists of spaces and tabs.
If you want to also remove newlines from the string, use the whitespaceAndNewlineCharacterSet:
NSString *newString = [oldString stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
No comments:
Post a Comment