ios
ios

Reputation: 6164

iPhone App:Selected text in uiwebview replace with some special character

In my iPhone App I have load .html file in uiwebview, when I am highlighting below text

enter image description here

1.   The income statement.

with code

NSString *selection = [self.wvNotes stringByEvaluatingJavaScriptFromString:@"window.getSelection().toString()"];

In log it gives me text as

enter image description here

1.\u00a0\u00a0\u00a0\u00a0\u00a0 The income statement.

It is replacing space with some \u00a0. what could be wrong?

Upvotes: 1

Views: 702

Answers (1)

tiguero
tiguero

Reputation: 11537

NSString *selection = [self.wvNotes stringByEvaluatingJavaScriptFromString:@"window.getSelection().toString()"];

is giving you a string that is encoded in unicode. As you have seen if you do an NSLog on this string it will print the non breaking space (. for the unicode string \u00a0). If you don't want those you can replace the unicode string with the space string " "

 NSString* stringToConvert = @"1.\u00a0\u00a0\u00a0\u00a0\u00a0 Test";
 stringToConvert = [stringToConvert stringByReplacingOccurrencesOfString:@"\u00a0" withString:@" "];
 // This will print "1.     Test"
 NSLog(stringToConvert);

Upvotes: 1

Related Questions