iPhone Development 101

iPhone 101

Code Tips

Resources

Links

More

Follow: TwitterRSS

iPhone Development 101: Objective-C: Strings:
Trim Spaces from the End of a String

This will remove white space from both ends of a string:

NSString *newString = [oldString stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet]];

The whitespaceCharacterSet consists of spaces and tabs. If you want to also remove newlines from the string, use the whitespaceAndNewlineCharacterSet:

NSString *newString = [oldString stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];

Additional References


TopHome