With copy/paste, one of my clients put in a textfield of my IOS app a text containing Zero Width Space [ E2 80 8B ] and I want to remove them.
here's an example of text : basse température avec dégivrage électrique
what I tried :
NSString* zarb = [NSString stringWithFormat:@"%c%c%c",0xE2,0x80,0x8B];
NSString*resu=[ch stringByReplacingOccurrencesOfString:zarb withString:@""];
// does not work
if ([ch rangeOfString:zarb].location != NSNotFound) {
// does not work
}
The hexa sequence IS in the string but I cannot remove it. Someone has already got this problem ?
To remove zero-width space characters from a JavaScript string, we can use the JavaScript string replace method that matches all zero-width characters and replace them with empty strings. Zero-width characters in Unicode includes: U+200B zero width space.
Use the str. replace() method to remove zero width space characters from a string, e.g. result = my_str. replace('\u200c', '') .
The "zero width space" is the Unicode character \U200B
. The E2 80 8B
is the UTF-8 encoding.
Try this:
NSString* zarb = @"\u200B";
NSString* resu = [ch stringByReplacingOccurrencesOfString:zarb withString:@""];
BTW - your attempt to do:
NSString* zarb = [NSString stringWithFormat:@"%c%c%c",0xE2,0x80,0x8B];
results in an invalid string because there are no Unicode characters for 80
and 8B
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With