NSString to wchar_t & wchar_t to NSString

-(NSString*)getStringFromWChar:(const wchar_t*) inStr{
    char *outStr = NULL;
    size_t size = wcstombs(NULL, inStr, 0);
    outStr = new char[size + 1];
    memset(outStr, 0, size * sizeof(char));
    size_t ret = wcstombs(outStr, inStr, size+1);
    if (ret == -1) {
        delete[] outStr;
        outStr = NULL;
    }
    NSString *string = [NSString stringWithCString:outStr encoding:NSUTF8StringEncoding];   
    return string;
}

-(wchar_t*)getWCharFromString:(NSString *)inStr{
    const char *cString = [inStr cStringUsingEncoding:NSUTF8StringEncoding];
    setlocale(LC_CTYPE, "UTF-8");
    wchar_t *outStr = NULL;
    size_t size = mbstowcs(NULL, cString, 0);
    outStr = new wchar_t[size + 1];
    if (outStr) {
        memset(outStr, 0, size * sizeof(wchar_t));
        size_t ret = mbstowcs(outStr, cString, size+1);
        if (ret == -1) {
            delete[] outStr;
			outStr = NULL;
        }
    }
    return outStr;
}

좋은 웹페이지 즐겨찾기