怎么将数组里的内容由gb2312转换成utf8
答案:2 悬赏:30 手机版
解决时间 2021-03-16 21:36
- 提问者网友:流星是天使的眼泪
- 2021-03-15 22:19
怎么将数组里的内容由gb2312转换成utf8
最佳答案
- 五星知识达人网友:英雄的欲望
- 2021-03-15 22:54
foreach ($arr as $k=>$v) {
$arr["$k"] = iconv('GB2312', 'UTF-8', $v);
}
$arr["$k"] = iconv('GB2312', 'UTF-8', $v);
}
全部回答
- 1楼网友:十年萤火照君眠
- 2021-03-16 00:05
比如实现utf-8和gb2312的转换:
string gb2312info = "你好!";
string utfinfo = string.empty;
encoding utf8 = encoding.utf8;
encoding gb2312 = encoding.getencoding("gb2312");
// convert the string into a byte[].
byte[] unicodebytes = gb2312 .getbytes(gb2312info );
// perform the conversion from one encoding to the other.
byte[] asciibytes = encoding.convert(gb2312,utf8, unicodebytes);
// convert the new byte[] into a char[] and then into a string.
// this is a slightly different approach to converting to illustrate
// the use of getcharcount/getchars.
char[] asciichars = new char[utf8 .getcharcount(asciibytes, 0, asciibytes.length)];
utf8 .getchars(asciibytes, 0, asciibytes.length, asciichars, 0);
utfinfo = new string(asciichars);
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯