Replace two or more spaces to  , 
How can I enc开发者_运维问答ode convert spaces to   in objective-c?
I need each space is replaced by  , except when only one space
Example
in text: AAA BBB C out text: AAAnbsp;nbsp;nbsp;nbsp;BBB C
thanks
Assuming you're talking about NSStrings -- look at the NSString documentation. There are instance methods for replacing strings of the form stringByReplacing...
Given that you use NSString
or NSMutableString
:
myString = [myString stringByReplacingOccurrencesOfString:@" " withString:@" "];
myString = [myString stringByReplacingOccurrencesOfString:@" " withString:@" "];
Yes, this needs to be done twice for the case of an odd number of spaces in a row.
If you are dealing with C-strings instead of NSString
s or NSMutableString
s, you do the same but with a function instead of a method. I am not going to write such a function here but know that you have to run it twice. :)
精彩评论