请问Objective-C中如何进行字符串编码转换?
对于GBK的网页,希望将其内容转换成UTF-8。
PHP中处理非常简单,但是Objective-C里却一直找不到办法。请问有没有办法来进行转码呢?谢谢!

解决方案 »

  1.   

    调用:GBKToUTF8(str对象, “gb2312”, “utf-8”);int GBKToUTF8(std::string & gbkStr, const char* toCode, const char* fromCode)
    {       iconv_t iconvH;
           iconvH = iconv_open(fromCode, toCode);
           if (iconvH == 0)
           {
                  return -1;
           }       const char* strChar = gbkStr.c_str();
           const char** pin = &strChar;
           size_t strLength = gbkStr.length();
           char* outbuf = (char*) malloc(strLength*4);
           char* pBuff = outbuf;       memset( outbuf, 0, strLength*4);
           size_t outLength = strLength*4;
           if (-1 == iconv(iconvH, pin, &strLength, &outbuf, &outLength))
           {
                  iconv_close(iconvH);
                  return -1;
           }
           gbkStr = pBuff;
           iconv_close(iconvH);
           return 0;
    }你试试