You could use a regex to remove whitespace from a string, with whitespace being anywhere in the string.
NSString *removeWhitespaceRegex = @"\\s";
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:removeWhitespaceRegex
options:NSRegularExpressionCaseInsensitive
error:&error];
NSString *string = @"Remove whitespace from this string.";
NSString *modifiedString = [regex stringByReplacingMatchesInString:string
options:0
range:NSMakeRange(0, [string length])
withTemplate:@""];
NSLog(@"%@", modifiedString);
Just a disclaimer, the code above is written by heart with a quick lookup of some methods, some things might not work, but the idea behind it should.
The second, probably quicker way is to use an NSCharacterSet
such as the JRG-Developer has mentioned, but this will remove only trailing whitespace.