In Cocoa Touch you always need to write more to achieve the same …
NSString *string = @" spaces in front and at the end "; NSString *trimmedString = [string stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]]; NSLog(trimmedString) |
While such a standard task might look excessively much code to write, you gain many additional possibilites of what you could want to trim away. NSCharacterSet also knows these other sets.
- alphanumericCharacterSet
- capitalizedLetterCharacterSet
- controlCharacterSet
- decimalDigitCharacterSet
- decomposableCharacterSet
- illegalCharacterSet
- letterCharacterSet
- lowercaseLetterCharacterSet
- newlineCharacterSet
- nonBaseCharacterSet
- punctuationCharacterSet
- symbolCharacterSet
- uppercaseLetterCharacterSet
- whitespaceAndNewlineCharacterSet
- whitespaceCharacterSet