Wednesday, June 8, 2011

iOS/ xCode /Objective-C Trim whitespace from string



//Remove spaces from both ends of a string

NSString *resultString = [yourString stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet]];


//To Remove spaces and newlines from the string, use the whitespaceAndNewlineCharacterSet

NSString *resultString = [yourString stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];

No comments:

Post a Comment

Kamleshwar