一、字符串类(QString)
(1)insetr()函数:在原字符串特定的位置插入另一个字符串。
(2)prepend()函数:在原定字符串的开头插入另一个字符串。
(3)replace()函数:用指定的字符串代替原字符串中的某些字符。
(4)QString::trimmed()函数:移除字符串两端的空白字符。
(5)QString::simplified()函数:移除字符串两端的空白字符,使用单个空格字符“”代替字符串中出现的空白字符。
eg:
QString str=" Welcome \t to \n you! “;
str=str.trimmed(); //str=“Welcome \t to \n you!”
如果使用str=str.simplified();则str的结果是“Welcome to you!”。
(6)QString::startsWith()/endsWith()判断一个字符串是否以某个字符串开头/结尾。
eg:
QString str=“Welcome to you!”;
str.startsWith(“Welcome”,Qt::CaseSensitive);//返回true;
str.startsWith(“you”,Qt::CaseSensitive);//返回false;
str.endsWith(“Welcome”,Qt::CaseSensitive);//返回true;
(7)QString::contains()判断一个指定的字符串是否出现过。
eg:
QString str=“Welcome to you!”;
str.contains(“Welcome”,Qt::CaseSensitive);//返回true;
(8)QString::append()函数具有与“+=”操作符同样的功能,实现在一个字符串的末尾追加另一个字符串
eg:
QString str1=“Welcome”;
QString str2=“to”;
str1.append(str2); //str1=“Welcome to”
str1.append(“you!”); //str1=“Welcome to you!”
字符串转换:QString::toInt()
eg:
QString str=“125”;
bool ok;
int hex=str.toInt(&ok,16); //ok=true,hex=293
int dec=str,toInt(&ok,10);//ok=true,dec=125
二、容器类
这样的数据类型包含了通常使用的大多数数据类型(如int等)和Qt的一些数据类型(QString等),不过Qt的QObject及其他的子类(QWidget和QDialog等)是不能存储在容