开发者

Critical NSSstring Problem in Facebook friend Recovery(IPhone Development)

开发者 https://www.devze.com 2023-03-19 13:47 出处:网络
My Question is regarding special Character in NSString. Actual name:-Yusuf Doğan Retrieve name=Yusuf Do\\u011fan

My Question is regarding special Character in NSString.

Actual name:- Yusuf Doğan

Retrieve name= Yusuf Do\u011fan

My Actual fb friend name is Yusuf Doğan (Check Special "g with ~ cap").

I take it as NSdata and then converter it in to nsstring.

NSString *stringResponse = [[NSString alloc] initWithData:response encoding:NSUTF8StringEnco开发者_如何学JAVAding];

But the nsstring shows it as

"Yusuf Do\u011fan"

Similar cause with the following.

Ricsi Zoványi as Ricsi Zov\u00e1nyi

Pero Perić as Pero Peri\u0107

Any Solution.

Thanks in advance.


You can try this:

        NSString *source = [NSString stringWithString:_username];
        [_username release];
        NSMutableString *result = [[NSMutableString alloc] init];
        NSScanner *scanner = [NSScanner scannerWithString:source];
        [scanner setCharactersToBeSkipped:nil];
        while (![scanner isAtEnd]) {
            NSString *chunk;

            // Scan up to the Unicode marker
            [scanner scanUpToString:@"\\u" intoString:&chunk];
            // Append the chunk read
            [result appendString:chunk];

            // Skip the Unicode marker
            if ([scanner scanString:@"\\u" intoString:nil]) {

                // Read the Unicode value (assume they are hexa and four)
                unsigned int value;
                NSRange range = NSMakeRange([scanner scanLocation], 4);
                NSString *code = [source substringWithRange:range];
                [[NSScanner scannerWithString:code] scanHexInt:&value];
                unichar c = (unichar) value;

                // Append the character
                [result appendFormat:@"%C", c];

                // Move the scanner past the Unicode value
                [scanner scanString:code intoString:nil];
            }
        }
        _username = [[NSString stringWithFormat:@"%@",result] retain];
        [result release];
    }


Instead of "NSUTF8StringEncoding" use "NSUTF16StringEncoding". I think this may solve your issue.

0

精彩评论

暂无评论...
验证码 换一张
取 消