当前位置:网站首页>Qt Utf8 与 Unicode 编码的互相转换, Unicode编码输出为格式为 &#xXXXX
Qt Utf8 与 Unicode 编码的互相转换, Unicode编码输出为格式为 &#xXXXX
2022-06-25 22:00:00 【北极熊的奋斗史】
先上结果:
utf-8文字: 这是测试文字123456abcdefg
Unicode码: 杩欐槸娴嬭瘯鏂囧瓧123456abcdefg
上代码:
1. utf8转Unicode码
QString utf8ToUnicode(const QString strUtf8)
{
QString strOut;
QString unidata = strUtf8;
for (int i = 0; i < unidata.length(); ++i)
{
ushort num = unidata[i].unicode();
if (num < 255)
strOut += unidata[i];
else
strOut += QString("&#x%1;").arg(QString::number(num, 16));
}
return strOut;
}2. Unicode转utf8
QString unicodeToUtf8(const QString strUnicode)
{
QString strOut = strUnicode;
int nPos = 0;
QRegExp rx("&#x([0-9,a-f|A-F]{4});");
while ((nPos = rx.indexIn(strOut, nPos)) != -1)
{
QChar qCh(rx.cap(1).toUShort(nullptr, 16));
strOut.replace(nPos, rx.matchedLength(), qCh);
nPos += 1;
}
return strOut;
}使用代码:
QString str = QString::fromLocal8Bit("5.6破坏的房屋和街区.svg");
QString strUnicode = utf8ToUnicode(str);
QString strUtf8 = unicodeToUtf8(strUnicode);
边栏推荐
- Repoptimizer: it's actually repvgg2
- Transformers load pre training model
- Count the number of different palindrome subsequences in the string
- 【opencv450-samples】读取图像路径列表并保持比例显示
- Implementation of importing vscode from PDM
- 漏刻有时API接口实战开发系列(13):小鹅通云服务PHP-API二维数组传参解决方案
- Ue4 Ue5 combine le plug - in de reconnaissance vocale de bureau pour la reconnaissance vocale
- Jupiter notebook common shortcut keys
- The sum of logarithms in group 52--e of Niuke Xiaobai monthly race (two points)
- How to add cartoon characters to the blog park?
猜你喜欢

Idea FAQ collection

LM small programmable controller software (based on CoDeSys) note XVII: PTO pulse function block

As a programmer, how can we learn, grow and progress happily? (personal perception has nothing to do with technology)

ES6 - numerical extension and object extension

Live800 online customer service system: do business across time and space, starting from each interaction

Paper notes: multi tag learning MSWl

为什么OpenCV计算的帧率是错误的?

论文笔记: 多标签学习 MSWL

多台云服务器的 Kubernetes 集群搭建

软件测试面试一直挂,面试官总是说逻辑思维混乱,怎么办?
随机推荐
Xampp重启后,MySQL服务就启动不了。
. SQL database import error: / *! 40101 SET @OLD_ COLLATION_ [email protected]@COLLATION_ CONNECTION */
Idea auto generator generates constructor get/set methods, etc
Unity technical manual - life cycle rotation rotationoverlifetime- speed rotation rotationbyspeed- and external forces
剑指 Offer 46. 把数字翻译成字符串(DP)
LM small programmable controller software (based on CoDeSys) note XVII: PTO pulse function block
Idea shortcut
干货丨产品的可行性分析要从哪几个方面入手?
Unity的Ping類使用
信息学奥赛一本通 1353:表达式括号匹配(stack) | 洛谷 P1739 表达式括号匹配
Flex & Bison Start
Day4 branch and loop summary and operation
Oracle - getting started
The applet draws a simple pie chart
CDN加速是什么
Recently prepared to translate foreign high-quality articles
#23class介绍
23class introduction
Pointer strengthening and improvement
[2023 proofreading and bidding questions] Part 1: Measurement Technology FPGA post (roughly analytical version)