请问如何将一个字符串从GBK转到UTF-8? 请问Objective-C中如何进行字符串编码转换?对于GBK的网页,希望将其内容转换成UTF-8。PHP中处理非常简单,但是Objective-C里却一直找不到办法。请问有没有办法来进行转码呢?谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 调用: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;}你试试 objective-C转C++ 怎么实现像91助手一样连上数据线就获得iphone的序列号 如果一个nsobject对象中含有基本数据类型的数组,relese的时候会发生什么? 交了99美元后怎么使用啊,付款已经成功。接下来怎么做 mac cocos2d-x安装问题 APP 应用软件提供商? 如何用object-c封装一些接口,提供C++或其他平台无关语言使用? Main.storyboard 文件的源代码在哪儿啊?先感谢前辈! h5页如何封装成可以上加的app CCb是什么 想学ipone开发 怎么实现iphone 弹出警告一样的动画效果
{ 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;
}你试试