//Qt 字符串操作(二) //转换//判空
#include <QCoreApplication>
#include<QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
//转换//toInt(bool地址,进制)//整型:toInt(&ok,10)//浮点数: toFloat(&ok).....
QString s1("125");
QString s2("125.345");
bool ok;
int h = s1.toInt(&ok);
int d = s1.toInt(&ok,10);
float f = s2.toFloat(&ok);
qDebug() << "s1的十六进制是 :" << h << " " << "s1的十进制是 :" << d << " " << f <<endl;
//QBitArray字节数组相当于C/C++里string和const char* 的结合可有或无'0'
//Qt5 toAclii()已被取消可用toLatin1()代替
QString s3("hello world");
QByteArray s4 = s3.toLatin1();
qDebug() << s4 << endl;
s4.append(" marco");
qDebug() << s4.data();
//判空//是空字符串或者本来就空的
QString s5;
qDebug() << s5.isNull() << s5.isEmpty() << endl;//ture//true
s5 = "";
qDebug() << s5.isNull() << s5.isEmpty() << endl;//false//true
return a.exec();
}