I know this is an old question, but yes, you can trim a mutable string without having to return a new string. You just need a regular expression, an example below:
NSMutableString *mutable = [NSMutableString stringWithString:@" String to trim \n"]; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\n| | $|^ " options:0 error:nil]; [regex replaceMatchesInString:mutable options:0 range:NSMakeRange(0, [mutable length]) withTemplate:@""];
source share