0030:Qt常用类 - QString(09,比较)

1 开发环境

在介绍内容之前,先说明一下开发环境,如下图:
在这里插入图片描述在这里插入图片描述
Qt版本:Qt5.3.2;
Qt开发工具:Qt Creater 3.2.1;
Qt构建工具:Desktop Qt 5.3 MinGW 32bit;
Qt开发平台:Windows 7 64bit。

2 QString

今天介绍QString的比较部分的功能,之前的内容可以参考以下链接。

0022:Qt常用类 - QString(01,QString的编码方式和初始化)
0023:Qt常用类 - QString(02,增加)
0024:Qt常用类 - QString(03,删除)
0025:Qt常用类 - QString(04,修改)
0026:Qt常用类 - QString(05,查询)
0027:Qt常用类 - QString(06,遍历)
0028:Qt常用类 - QString(07,子字符串)
0029:Qt常用类 - QString(08,格式化)

下面是比较部分的示例代码。

/*
 * compare(const QString &other, Qt::CaseSensitivity cs)
 * localeAwareCompare(const QString &other)
 * operator==(const char *other)
 * operator<(const char *other)
 * operator<=(const char *other)
 * operator>(const char *other)
 * operator>=(const char *other)
*/
//compare(const QString &other, Qt::CaseSensitivity cs)
QString strComp = "12345abcde一二三四五";
qDebug("compare: result = %d.", strComp.compare("12345abcde一二三四五"));

//localeAwareCompare(const QString &other)
qDebug("localeAwareCompare: result = %d.", strComp.localeAwareCompare("23456"));

//operator==(const char *other)
qDebug("==: result = %d.", strComp == "23456abcde一二三四五");

//operator<(const char *other)
qDebug("<: result = %d.", strComp < "23456abcde一二三四五");

//operator<=(const char *other)
qDebug("<=: result = %d.", strComp <= "12345abcde一二三四五");

//operator>(const char *other)
qDebug(">: result = %d.", strComp > "23456abcde一二三四五");

//operator>=(const char *other)
qDebug(">=: result = %d.", strComp >= "23456abcde一二三四五");

在学习过程中,可以将上述代码放到一个按钮的响应函数中,以调试方式运行,就可以在Qt Creater中的应用程序输出窗口看到输出结果了。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值