QString拼接

QString str1 = "Welcome";//传递一个const char* 类型的ASCII字符“Welcome”,会调用QString的构造函数
str1 = str1 + " to you!";
qDebug()<< str1;

QString str1 = "Welcome";
QString str2 = " to";
str1. append(str2);
str1.append(" you!");
qDebug()<< str1;

QString str;
str. sprintf("%s"," Welcome");
qDebug()<< str;

str.sprintf("%s"," to you!");
qDebug()<< str;
str.sprintf("%s %s","Welcome"," to you!");
qDebug()<< str;
QString str;

str = QString("%1 was born in %2"). arg("John").arg(1988);
qDebug()<< str;

str. insert(1,"IS ");//在指定位置插入字符串
str. prepend("ABC ");//在字符串开头位置插入字符串
qDebug()<< str;

你可能感兴趣的:(QT学习笔记)