#include <QtCore/QCoreApplication>
#include <QDebug>
#include <QTextCodec>
#include <QStringList>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QTextCodec *code=QTextCodec::codecForLocale();
QTextCodec::setCodecForCStrings(code);
QTextCodec::setCodecForLocale(code);
QTextCodec::setCodecForTr(code);
QString str001="hello IT小子!";
qDebug()<<"str content--->"<<str001;
qDebug()<<"str size------>"<<str001.size(); //字符个数
str001.append("Goodbye!");
qDebug()<<"str content--->"<<str001;
str001.insert(9,"hehe,");
qDebug()<<"str content--->"<<str001;
str001.replace(9,4,"走起");
qDebug()<<"str content--->"<<str001;
str001+="---输入未知---";
qDebug()<<"str content--->"<<str001;
QString str002="\f\t hei hei";
qDebug()<<"str002 content--->"<<str002;
qDebug()<<"str002 simplified--->"<<str002.simplified();//此处内部空行取消不了
qDebug()<<"str002 trimmed--->"<<str002.trimmed(); // \f 出现的符号消失,trimed将符号和空格都去掉了
QString str003="one,two,three,,,";
QStringList strlist=str003.split(',',QString::SkipEmptyParts);
qDebug()<<strlist;
QStringList list;
list<<"早上好"<<"早起的鸟有虫吃"<<"Nice"<<"说得对!";
QString str004=list.join("->");
qDebug()<<str004;
qDebug()<<str004.isEmpty();
qDebug()<<str004.isNull();
QString str005;
qDebug()<<str005.isEmpty();
qDebug()<<str005.isNull();
int str006=10000;
QString str007=QString::number(str006);
qDebug()<<str007;
QString str008=QString("some string is %1 , %2 , %3 and others!").arg(str001).arg(str002).arg(str003);
qDebug()<<str008;
return a.exec();
}
运行效果: