There is method for that in NSString class. Check stringByTrimmingCharactersInSet:(NSCharacterSet *)set
. You should use [NSCharacterSet whitespaceCharacterSet]
as parameter:
NSString *foo = @" untrimmed string ";
NSString *trimmed = [foo stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…