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
Categories: Recipes
Nice one
Just when I needed it.
You saved my day!
[...] Remove Whitespace from NSString | Cocoanetics strip the whitespace&newlines from your text [...]
[...] The corresponding code that follows along with what you just described would be nice. Also, when using url's that you parse out of this config file, a lot of people seem to have problems regarding white space with the url that causes problems later down the road. I suspect this may be happening to you. Be sure and do a trim on the url NSString's that you get out of your config file before your loadXML. Remove Whitespace from NSString | Cocoanetics [...]
Very helpful