Reputation: 4025
I am drawing text to a UIView using drawInRect:. I obtain the text to draw from a server side script. In at least one case, the character \U00a0 is found in the string that I am receiving from the server and that single character is breaking the drawInRect: method. Meaning, it will draw all of the text up until that character, but will not draw any text past that character. Does anyone have any idea what that character is? I did some Googling and learned that the character is the non-breaking space in unicode, although when I NSLog the string, the character shows up as a middle dot. Below is an example of the string that I get back from the server. It is riddled with \n and \t (another thing I am trying to clean up), but you can see the \U00a0 about half way through.
\n\tDescription
\n
\n\t\U00a0
\n
\n\t
Any help would be appreciated. Bonus points if you can figure out a way for me to remove it from the string.
Upvotes: 2
Views: 705
Reputation: 4025
This appears to have been an odd byproduct of using GTMNSString+HTML.h to unescape HTML characters. The character originally was in fact a non-breaking HTML space, , and got converted to \u00a0 in the process of using gtm_stringByUnescapingFromHTML. As long as I strip the string of before running gtm_stringByUnescapingFromHTML, everything appears to be fine.
Upvotes: 0
Reputation: 89559
Take a look at the answers in this related question:
Remove characters from NSString?
I'm thinking you should be able to put your string into a NSMutableString
object and then remove the offending characters by using NSMutableString's replaceOccurencesOfString: withString: options: range:
method and just @"\U00A0"
as the string to be replaced.
Upvotes: 1