0026:Qt常用类 - QString(05,查询)

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,修改)

下面是查询部分的示例代码。

/*
 * contains(const QString &str, Qt::CaseSensitivity cs)
 * contains(QChar ch, Qt::CaseSensitivity cs)
 * endsWith(const QString &s, Qt::CaseSensitivity cs)
 * endsWith(QChar c, Qt::CaseSensitivity cs)
 * indexOf(const QString &str, int from, Qt::CaseSensitivity cs)
 * indexOf(QChar ch, int from, Qt::CaseSensitivity cs)
 * lastIndexOf(const QString &str, int from, Qt::CaseSensitivity cs)
 * lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs)
 * startsWith(const QString &s, Qt::CaseSensitivity cs)
 * startsWith(QChar ch, Qt::CaseSensitivity cs)
*/
//contains(const QString &str, Qt::CaseSensitivity cs)
QString strQuery = "abcdeABCDE一二三四五";
qDebug("strQuery.contains(\"abcdE\") = %d.", strQuery.contains("abcdE"));

//contains(QChar ch, Qt::CaseSensitivity cs)
qDebug("strQuery.contains(QChar('e')) = %d.", strQuery.contains(QChar('e')));

//endsWith(const QString &s, Qt::CaseSensitivity cs)
qDebug("strQuery.endsWith(\"一二三四五\") = %d.", strQuery.endsWith("一二三四五"));

//endsWith(QChar c, Qt::CaseSensitivity cs)
qDebug("strQuery.endsWith(QChar('e')) = %d.", strQuery.endsWith(QChar('e')));

//indexOf(const QString &str, int from, Qt::CaseSensitivity cs)
qDebug("strQuery.indexOf(\"一二三四五\") = %d.", strQuery.indexOf("一二三四五"));

//indexOf(QChar ch, int from, Qt::CaseSensitivity cs)
qDebug("strQuery.indexOf(QChar('e')) = %d.", strQuery.indexOf(QChar('e')));

//lastIndexOf(const QString &str, int from, Qt::CaseSensitivity cs)
qDebug("strQuery.lastIndexOf(\"一二三四五\") = %d.", strQuery.lastIndexOf("一二三四五"));

//lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs)
qDebug("strQuery.lastIndexOf(QChar('e')) = %d.", strQuery.lastIndexOf(QChar('e')));

//startsWith(const QString &s, Qt::CaseSensitivity cs)
qDebug("strQuery.startsWith(\"abcde\") = %d.", strQuery.startsWith("abcde"));

//startsWith(QChar ch, Qt::CaseSensitivity cs)
qDebug("strQuery.startsWith(QChar('e')) = %d.", strQuery.startsWith(QChar('e')));

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值