When trying to append to an NSMutableString with appendFormat – It adds spaces.
NSM is just an NSMutableString, att_1_variable & att_2_variable is NSString
[NSM appendFormat:@"<tagname att_1=\" %@ \" att_2=\" %@ \">", att_1_variable, att_2_variable];
The result is:
<tagname myattribute=" ContentOfVariable " title=" ContentOfVariable ">
Before passing in the strings I am doing:
NSString* att_1_variable = [att_1_variable_orginal stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]];
Is there any way around this?
Thanks
Regards
Christian
You’re adding the spaces yourself, by including them in the format string. In C the escape sequence for a quotation mark is just
\", with no trailing (or leading) space. So you want:If there are spaces between the quotation marks and the variable contents after that then your input variables are padded with spaces. You can trim those with something like:
Which will trim spaces and tabs from both ends.