Convert wchar_t* to NSString
        Posted  
        
            by Sharath
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Sharath
        
        
        
        Published on 2010-06-15T05:40:40Z
        Indexed on 
            2010/06/15
            5:42 UTC
        
        
        Read the original article
        Hit count: 1055
        
objective-c
|mac
Trying to convert const wchar_t * to NSString. The following code only produces the first character. I've tried the different CFAllocator options as well but with no success. Can anyone help me or point to how I can convert wchar_t * to NSString
const wchar_t *data = L"Hello World";
int l = wcslen(data);
    CFStringRef c = CFStringCreateWithCharacters(kCFAllocatorSystemDefault,
                                                 (const UniChar *) data,l);
NSString *nStr = (NSString *)c; //This always gives me 'H'
        © Stack Overflow or respective owner