此篇博客核心介绍QT中的QString类型的常用函数,介绍到的函数均从帮助手册或其他博客中看到
QString 字符串类
Header: |
#include |
qmake: |
QT += core |
int toInt(bool *ok = Q_NULLPTR, int base = 10) const
long toLong(bool *ok = Q_NULLPTR, int base = 10) const
short toShort(bool *ok = Q_NULLPTR, int base = 10) const
uint toUint(bool *ok = Q_NULLPTR, int base = 10) const
ulong toUlong(bool *ok = Q_NULLPTR, int base = 10) const
注:上述函数参数缺省时,缺省表示从十进制的字符串转换为整型,如果指定参数,则可以将二进制、十六进制字符串转换为整数。
double toDouble(bool *ok = Q_NULLPTR) const
float toFloat(bool *ok = Q_NULLPTR) const
Qstring &setNum(int n, int base = 10)
Qstring number(int n,int base = 10)
QString &append(const QString &s)
QString &prepend(const QString &s)
QString &replace(int i, int len, const QString &after)
QString &replace(const QString &before, QLatin1String after, Qt::CaseSensitivity cs = Qt::CaseSensitive)
QString &insert(int i, const QString &s)
void chop(int n)
QString &remove(int i, int len)
QString &remove(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive)
QString toUpper() const
QString toLower() const
int count() const
int size() const
int length() const
QString trimmed() const
QString simplified() const
int indexOf(const QString &s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
注:from:开始查找的位置 cs:是否区分大小写
int lastIndexOf(const QString &s, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool isNull()
bool isEmpty()
//注:如果字符串内只有"\0",isNull()返回false,isEmpty() 返回true
bool contains(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
//注:c:要查询的字符串 cs:大小写
bool startsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
bool endsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
QString left(int n) const
QString right(int n) const
QString section(const QString &in_sep, int start, int end = -1, SectionFlags flags = SectionDefault) const
//从字符串中提取in_sep作为分隔符,分割从start端到end端的字符串。
QString() :默认构造函数
QString(const char *str) :带参构造,把str字符串的内容赋值给QString
void clear() //清空字符串
QString QString::mid(int position, int n = -1) //取中间字符串
QStringList split(const QString &sep) //切割后返回字符串链表