about this site
V2EX is the personal blog of Xin Livid Liu.
Xin is an iPhone developer. His wife Olivia and he are enjoying inspirations in their OLIVIDA Studio.
Xin is an iPhone developer. His wife Olivia and he are enjoying inspirations in their OLIVIDA Studio.
archives
tags
- Adium
- Anime
- Apple
- App Store
- Beginning
- Beta
- cocos2d
- Code
- Code Geass
- Cydia
- Design
- Example
- FAQ
- Games
- Gomoku
- Hangzhou
- Interface Builder
- iPhone
- iPhone Developer Program
- Jabber
- Java
- Live
- MacBook Pro
- Nonsense
- NSString
- nVIDIA
- Performance
- Smack
- SQLite
- Themes
- Thinking
- Trip
- Tutorial
- UIActionSheet
- UIImageView
- UITableView
- UITableViewCell
- UIView
- UIViewController
- V2EX
- Video
- WordPress
- Xcode
- XMPP
links
Tag:
NSString
Posted in iPhone on September 22nd, 2008 by Xin
Trimming leading and trail whitespace is common for data parsed from XML or JSON, however, there isn’t an equivalent method like PHP’s trim() in Objective-C, but with categories it’s easy to add functions to existing classes like NSString.
NSString+trim.m implements a class method + (NSString *)trim:(NSString *)original extends NSString to do the same thing as PHP’s trim(). Download the zip, drag NSString+trim.h and NSString+trim.m to your project and use it like this:
#import "NSString+trim.h"
NSString * trimmed = [NSString trim:whatever]; // whatever is NSString from XML or anything that needs to be trimmed
Download: NSString+trim.zip
It works on both iPhone and Mac.

