Frage

I have encountered a really odd behavior:

NSLog(@"substring: '%@'\t- length: %d",substring,substring.length);

returns

substring: '‍'  - length: 1

The substring variable is a NSString object.

Can someone please explain what is going on...

EDIT :: SOLVED

As Amy answered:

It's printing an invisible character.: ‍

ZERO WIDTH JOINER Unicode: U+200D, UTF-8: E2 80 8D

if ([substring isEqualToString:@"\u200d"]) {
    NSLog(@"It is a ZERO WIDTH JOINER...");
}

And thanks to Phillip for the tip.

War es hilfreich?

Lösung

It's printing an invisible character.:

‍ ZERO WIDTH JOINER Unicode: U+200D, UTF-8: E2 80 8D

Andere Tipps

What about invisible space? You should check your substring for U+200B symbol, or take a look here http://www.cs.tut.fi/~jkorpela/chars/spaces.html

Might be some kind of whitespace. If you want to ignore whitespace, you can try:

string = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

I had to trim using the following to get rid of some extra invisibles.

[[NSCharacterSet alphanumericCharacterSet] invertedSet]
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top