1.QString
在c++標(biāo)準(zhǔn)庫中有2種類型的字符串char*和std::string
QT則提供了對象QString
QString除了具備字符串對象一般功能函數(shù)之外還提供了自己特有的功能比如:
str.sprintf("%s %.1f%%", "perfect competition", 100.0); ---格式化輸出
當(dāng)然也可以使用匿名形式
str = QString("%1 %2 (%3s-%4s)").arg("permissive").arg("society").arg(1950).arg(1970);
%1,%2,%3是占位符
另外QString還提供了一系列類型類型裝換函數(shù)比如:
str = QString::number(59.6);
str.setNum(59.6);
當(dāng)然還有其他功能
下面是具體的測試?yán)?
#include <QtCore/QCoreApplication>
#include <QString>
#include <QtDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString str;
str.append("Hello QT");
qDebug()<<str.left(3);
qDebug()<<str.right(3);
qDebug()<<str.mid(2,2);
qDebug()<<str.mid(2);
qDebug()<<str.indexOf("QT");
qDebug()<<str.startsWith("Hello");
qDebug()<<str.toLower();
str.replace(" ","O(∩_∩)O~");
qDebug()<<str;
str.insert(0,"....");
qDebug()<<str;
str.remove(0,3);
qDebug()<<str;
str = QString("%1%2%3").arg("1").arg(2).arg("3");
qDebug()<<str;
return a.exec();
}
當(dāng)然還有其他它功能
2.QByteArray
QByteArray是比特?cái)?shù)組
為了掌握它的基本功能還是測試下功能大致就知道了
#include <QtCore/QCoreApplication>
#include <QByteArray>
#include <QtDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QByteArray arr;
arr.append("123");
qDebug()<<arr.at(2);
arr = "lots\t of\nwhitespace\r\n ";
qDebug()<<arr;
qDebug()<<arr.simplified();
qDebug()<<arr;
arr.chop(3);
qDebug()<<arr;
qDebug()<<arr.count();
qDebug()<<arr.isEmpty();
qDebug()<<arr.isNull();
arr.fill(244,10);
qDebug()<<arr;
return a.exec();
}