[英]Check Hexadecimal Representation of a QByteArray
How does one check for specific values in a QByteArray? 如何检查QByteArray中的特定值?
Something like this: 像这样:
QByteArray example;
//...
example = file.readAll();//fill with data from a file
//...
if(example.mid(0, 2) == 0x0a00)
//do something
The above doesn't work. 上面的方法不起作用。
I CAN do this but I am currently fixing performance issues so I'd rather not have to convert it to a QString: 我能做到这一点,但我目前解决性能问题,所以我宁愿没有将其转换为QString:
QByteArray example;
//...
example = file.readAll();//fill with data from a file
//...
if(example.mid(0, 2).toHex() == "0a00")
//do something
What's the fastest way to check the bytes in a QByteArray based on their hex representation? 根据十六进制表示法检查QByteArray中字节的最快方法是什么?
You can compare simply like this. 您可以像这样简单地进行比较。
if(example.mid(0, 2) == "\\x0a\\x00") if(example.mid(0,2)==“ \\ x0a \\ x00”)
Edited: This is not working. 编辑:这是行不通的。 Check below comment. 检查以下评论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.