当前位置:网站首页>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);
边栏推荐
- How to use drawing comparison function in CAD
- UE4_ Ue5 combines the offline voice recognition plug-in for speech recognition
- Circuit module analysis exercise 5 (power supply)
- Circuit module analysis exercise 6 (switch)
- 记录一下Qt将少量图片输出为MP4的思路及注意事项
- ACM. HJ16 购物单 ●●
- 头歌 第3关:使用线程锁(Lock)实现线程同步
- Leetcode(605)——种花问题
- Exclusive or operator simple logic operation a^=b
- 百度:2022年十大热度攀升专业出炉,第一名无悬念!
猜你喜欢

Circuit module analysis exercise 6 (switch)

我的vscode

Meta universe standard forum established

1281_ FreeRTOS_ Implementation analysis of vtaskdelayuntil

Ble Low Power Bluetooth networking process and Bluetooth role introduction

【AXI】解读AXI协议原子化访问

Network security project questions of the first Henan vocational skills competition in 2022

Fastjson deserialization randomness failed

CTS RTS RX TX in serial port flow control UART (direct communication between serial port module and MCU)

Rk3568+ Hongmeng industrial control board industrial gateway video gateway solution
随机推荐
App new function launch
Equivalence class, boundary value, application method and application scenario of scenario method
UE4_ Ue5 combines the offline voice recognition plug-in for speech recognition
How to use JMeter for interface testing
干货丨产品的可行性分析要从哪几个方面入手?
Sword finger offer 46 Translate numbers to strings (DP)
ACM. HJ16 购物单 ●●
Comp212 distributed protocol
cookie、session、token
Circuit module analysis exercise 6 (switch)
Unity的Ping类使用
Recently prepared to translate foreign high-quality articles
Es6-- set
Why is BeanUtils not recommended?
汇编语言核心要点
【无标题】打开一个项目连接,无法正常显示时,ping一下ip
LM small programmable controller software (based on CoDeSys) note XVII: PTO pulse function block
No absurd tea applet - rule change
. SQL database import error: / *! 40101 SET @OLD_ COLLATION_ [email protected]@COLLATION_ CONNECTION */
软件测试面试一直挂,面试官总是说逻辑思维混乱,怎么办?