QChar 表示一个字符的类,包含于QtCore
判断:
bool isDigit() const;//判断是否是十进制数字('0'-'9')
bool isLetter() const;//判断是否是字母
bool isNumber() const;//判断是否是数字,包括正负号,小数点等
bool isLetterOrNumber() const;//判断力是否是字母或数字
bool isLower() const;判断是否是小写字母
bool isUpper() const;//判断是否是大写字母
bool isNull() const;//判断是否是空字符'0'
bool isPrint() const;//判断是否是可打印字符
bool isSpace() const;//判断是否是分隔符,包括空格等
转换:
char toAscii() const;//得到字符的ASCII码
QChar toLower() const;//转换成小写字母
QChar toUpper() const;转换成大写字母
ushort unicode() const;//得到Unicode编码
比较:
bool operator != (QChar c1, QChar c2);//判断c1是否不等于c2
bool operator < (QChar c1, QChar c2);// ......是否小于...
bool operator <= (QChar c1, QChar c2);
bool operator == (QChar c1, QChar c2);
bool operator > (QChar c1, QChar c2);
bool operator >= (QChar c1, QChar c2);
QString 表示字符串的类,包含于QtCore
判断: bool isEmpty() const; //判断是否为空字符串
转换: 将字符串转换成数值
double toDouble(bool *ok = 0) const;//ok参数指向一个bool型变量,这个参数用于指出转换是否成功的信息.
float toFloat(bool *ok = 0) const;
int toInt(bool *ok = 0, int base = 10) const;//base则有是转换成整数类型时的基,十进制就是10,八进制就是8
long toLong(bool *ok = 0, int base = 10) const;//长整型数
short toShort(bool *ok = 0, int base = 10) const;//短整型数
uint toUInt(bool *ok = 0, int base = 10) const;
ulong toULong(bool *ok = 0, int base = 10) const;
ushort otUShort(bool *ok = 0, int base = 10) const;
QString toLower() const;//转换为小写
QString toUpper() const;//转换成大写
比较:
int compare(const QString &s1, const QString &s2,
Qt::CaseSensitivity cs = Qt::CaseSensitive );//比较两个字符串,
参数cs有两个取值, Qt::CaseInsensitive表示对大小写不敏感 Qt::CaseSensitive表示敏感
返回值的含义:大于0表示s1大于s2,等于0表示相等,小于0表示小于
查找:
bool contains(const QString &str(或QChar ch),
Qt::CaseSensitivity cs = Qt::CaseSensitive) const;//判断QString对象是否包含指定的字符串或字符
int count(const QString &str(或QChar ch),
Qt::CaseSensitivity cs = Qt::CaseSensitive) const;//得到包含某特定字符串或字符个数
int indexOf(const QString &str(或QChar ch), int from = 0,//from是查找的起点
Qt::CaseSensitivity cs = Qt::CaseSensitive) const;//得到某个特定字符串或字符位置
字符串处理:
QString &operator = (const QString &other);//复制另外一个QString对象other
QString &operator = (const char *str);//复制普通字符串
QString &operator = (char ch);//复制字符
QString &operator = (QChar ch);//复制QChar类对象
以下函数可将另一个字符串或字符接在QString对象后面,形成一个整体的字符串:
QString &append(const QString &str);接续QString对象
QString &append(const char *str);//接续普通字符串
QString &append(QChar ch);//接续QChar对象
!!如果把append换成prepend,则表示接在原字符串的前面
!!!!!用法:如: QString str; str.append("hello");就表示在str后面接上"hello"
在QString对象的任意位置插入另一个字符串或字符:
QString &insert(int position, const QString &str);插入字符串
QString &insert(int position, const QChar *pch, int size);//插入QChar数组
QString &insert(int position, QChar ch);//插入QChar对象
QString &remove(int position, int n);//移除QString对象中从位置position开始的n个字符
QString &remove(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive);//这个和下面的句子都是移除指定的字符串或字符
QString &remove(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive
替换操作: 将QString对象从position开始的n个字符替换为新内容
QString &replace(int position, int n, const QString &after);//替换QString对象
QString &replace(int position, int n, const QChar *pch, int size);//替换QChar数组
QString &replace(int position, int n, QChar after);//替换QChar对象
如果形如:QString &replace(const QString &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive);则可以搜索指定的字符串或字符进行替换
清空一个QString对象的内容,使这成为空字符串: void clear();
截断QString对象,也就是去年指定位置后的所有内容: void truncate