QT5笔记:13. QString 的常用功能
QString采用Unicode码,所以任何一个字符不管中英文,在size或者count时都算作一个字符,不会有宽字符区分
常用的方法
- append
- prepend
- toUpper
- toLower
- left
- right
- section
- simplified
- trimmed
- count
- size
- indexOf
- lastIndexOf
- endsWith
- startsWith
- contains
- isNull
- isEmpty
#include "widget.h"
#include "ui_widget.h" Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
} Widget::~Widget()
{
delete ui;
} void Widget::on_btnAppend_clicked()
{
QString str1 ,str2;
str1 = ui->comboBoxStr1->currentText();//G:\Qt5Book\QT5.9Study
str2 = ui->comboBoxStr2->currentText();//一个反斜杠
str1 = str1.append(str2);
ui->editResult->setText(str1);
} void Widget::on_btnPrepend_clicked()
{
QString str1 ,str2;
str1 = ui->comboBoxStr1->currentText();
str2 = ui->comboBoxStr2->currentText();
str1 = str1.prepend(str2);
ui->editResult->setText(str1);
} void Widget::on_btnUpper_clicked()
{
QString str1 = ui->comboBoxStr1->currentText();
str1 = str1.toUpper();
ui->editResult->setText(str1);
} void Widget::on_btnLower_clicked()
{
QString str1 = ui->comboBoxStr1->currentText();
str1 = str1.toLower();
ui->editResult->setText(str1);
} void Widget::on_btnLeft_clicked()
{
QString str1 = ui->comboBoxStr1->currentText();
int number = ui->spinBoxResult->value();
str1 = str1.left(number);
ui->editResult->setText(str1);
} void Widget::on_btnRight_clicked()
{
QString str1 = ui->comboBoxStr1->currentText();
int number = ui->spinBoxResult->value();
str1 = str1.right(number);
ui->editResult->setText(str1);
} /**
* section
* @brief Widget::on_btnSection_clicked
* @note sep表示用来切割的字符,start表示开始切割的位置,end表示切割的结束位置,flag参数可以用来影响函数的行为的某些方面,例如是否区分大小写,是否跳过空字段和如何处理前导和尾随分隔符。
* @result 结果返回开始切割那个字符到结束切割的那个字符之后的那个字符串。
* @note 当start 或者 end的参数为负数时,表示起始位置为右边。
* @note 相当于先split()进行切割,拿到各个片段(都是数组),然后取出index为start到end的数组内容,然后组装成一个字符串
*/
void Widget::on_btnSection_clicked()
{
QString str1 ,str2;
str1 = ui->comboBoxStr1->currentText();
str2 = ui->comboBoxStr2->currentText();
int number = ui->spinBoxResult->value();
str1 = str1.section(str2.data()[0],number,number +1);
ui->editResult->setText(str1);
} /**
* @brief Widget::on_btnSimplified_clicked
* @note 将字符串的开头和结尾的空白字符(\t、\r、\n、\f、空格)去掉,然后字符串中间的若有多个空格相连,则只保留一个
*/
void Widget::on_btnSimplified_clicked()
{
QString str1 = ui->comboBoxStr1->currentText();
str1 = str1.simplified();
ui->editResult->setText(str1);
} /**
* @brief Widget::on_btnTirm_clicked
* @note 将字符串开头和结尾的空白字符(\t、\r、\n、\f、空格)去掉
*/
void Widget::on_btnTirm_clicked()
{
QString str1 = ui->comboBoxStr1->currentText();
str1 = str1.trimmed();
ui->editResult->setText(str1);
} /**
* @brief Widget::on_btnCount_clicked
* @note Returns the number of (potentially overlapping) occurrences of the string str in this string.
*/
void Widget::on_btnCount_clicked()
{
QString str1 = ui->comboBoxStr1->currentText();
int count = str1.count();
ui->editResult->setText(str1.setNum(count));
} /**
* @brief Widget::on_btnSize_clicked
* @note string的大小:Returns the number of characters in this string.
*/
void Widget::on_btnSize_clicked()
{
QString str1 = ui->comboBoxStr1->currentText();
int size = str1.size();
ui->editResult->setText(str1.setNum(size));
} /**
* @brief Widget::on_binIndexOf_clicked
* @note 第一次出现的index
*/
void Widget::on_binIndexOf_clicked()
{
QString str1 ,str2;
str1 = ui->comboBoxStr1->currentText();
str2 = ui->comboBoxStr2->currentText();
int index = str1.indexOf(str2);
str1 = str1.setNum(index);
ui->editResult->setText(str1);
} /**
* @brief Widget::on_btnLastIndex_clicked
* @note 最后一次出现的index
*/
void Widget::on_btnLastIndex_clicked()
{
QString str1 ,str2;
str1 = ui->comboBoxStr1->currentText();
str2 = ui->comboBoxStr2->currentText();
int index = str1.lastIndexOf(str2);
str1 = str1.setNum(index);
ui->editResult->setText(str1);
} /**
* @brief Widget::on_btnEndWith_clicked
* @note 是否是以str2结尾
*/
void Widget::on_btnEndWith_clicked()
{
QString str1 ,str2;
str1 = ui->comboBoxStr1->currentText();
str2 = ui->comboBoxStr2->currentText();
bool result = str1.endsWith(str2);
ui->checkBoxResult->setText(qobject_cast<QPushButton *>(sender())->text());
ui->checkBoxResult->setChecked(result);
} /**
* @brief Widget::on_btnStartsWith_clicked
* @note 是否以str2开始
*/
void Widget::on_btnStartsWith_clicked()
{
QString str1 ,str2;
str1 = ui->comboBoxStr1->currentText();
str2 = ui->comboBoxStr2->currentText();
bool result = str1.startsWith(str2);
ui->checkBoxResult->setText(qobject_cast<QPushButton *>(sender())->text());
ui->checkBoxResult->setChecked(result);
} /**
* @brief Widget::on_btnContains_clicked
* @note 是否存在str2
*/
void Widget::on_btnContains_clicked()
{
QString str1 ,str2;
str1 = ui->comboBoxStr1->currentText();
str2 = ui->comboBoxStr2->currentText();
bool result = str1.contains(str2);
ui->checkBoxResult->setText(qobject_cast<QPushButton *>(sender())->text());
ui->checkBoxResult->setChecked(result);
} /**
* @brief Widget::on_btnIsNull_clicked
* 是否是null,区别于空字符串和空白字符串
*/
void Widget::on_btnIsNull_clicked()
{
QString str1 = ui->comboBoxStr1->currentText();
bool result = str1.isNull();
ui->checkBoxResult->setText(qobject_cast<QPushButton *>(sender())->text());
ui->checkBoxResult->setChecked(result);
} /**
* @brief Widget::on_btnIsEmpty_clicked
* 是否是空字符串
*/
void Widget::on_btnIsEmpty_clicked()
{
QString str1 ,str2;
str1 = ui->comboBoxStr1->currentText();
bool result = str1.isEmpty();
ui->checkBoxResult->setText(qobject_cast<QPushButton *>(sender())->text());
ui->checkBoxResult->setChecked(result);
}界面:

QT5笔记:13. QString 的常用功能的更多相关文章
- Wireshark学习笔记(一)常用功能案例和技巧
@ 目录 常用功能 1.统计->捕获属性 2.统计->协议分级 3.过滤包Apply as filter E1:过滤出特定序号的包 E2:过滤出某IP地址或端口 E3:导出php文件 E4 ...
- 【笔记】sublime 一些常用功能和快捷键
Ctrl+D 选词 (反复按快捷键,即可继续向下同时选中下一个相同的文本进行同时编辑)Ctrl+G 跳转到相应的行Ctrl+J 合并行(已选择需要合并的多行时)Ctrl+L 选择整行(按住-继续选择下 ...
- JAVA自学笔记13
JAVA自学笔记13 1.StringBuffer类 1)线程安全的可变字符序列 线程安全(即同步) 2)StringBuffer与String的区别:一个可变一个不可变 3)构造方法: ①publi ...
- [Java] JSP笔记 - EL、JSTL 常用标签
一. 什么是 EL 语言 表达式语言(EL)是 JSP 2.0 引入的一种计算和输出 Java 对象的简单语言. 二.EL 语言的作用 为了使JSP写起来更加简单.表达式语言的灵感来自于 ECMASc ...
- python3 字符串与列表常用功能
一.字符串常用功能 1. capitalize(),将字符串的首字母变成大写,其余全部置为小写:如果字符串中有多个单词,也只是将第一个单词的首字母置为大写:例: >>> name = ...
- Ext.Net学习笔记13:Ext.Net GridPanel Sorter用法
Ext.Net学习笔记13:Ext.Net GridPanel Sorter用法 这篇笔记将介绍如何使用Ext.Net GridPanel 中使用Sorter. 默认情况下,Ext.Net GridP ...
- JavaSE学习总结第13天_API常用对象3
13.01 StringBuffer的概述 StringBuffer类概述:线程安全的可变字符序列.一个类似于 String 的字符串缓冲区,但不能修改.虽然在任意时间点上它都包含某种特定的字符序 ...
- 前端开发掌握nginx常用功能之rewrite
上一篇博文对nginx最常用功能的server及location的匹配规则进行了讲解,这也是nginx实现控制访问和反向代理的基础.掌握请求的匹配规则算是对nginx有了入门,但是这些往往还是不能满足 ...
- Linux系统Bash的常用功能(9)
了解了基本的Linux文件文件系统的概念后,我们将更深入的了解一下Linux的其他方面的内容,那就是我们所使用的用户接口,也就是大家常听到的 『Shell』 ,『这个shell并不是黑客反弹的shel ...
- 160229-01、web页面常用功能js实现
web页面常用功能js实现 1.网页未加载时弹出新窗口 <body onunload="window.open('http://www.a68.cn');">< ...
随机推荐
- QEMU CVE-2021-3947 和 CVE-2021-3929 漏洞利用分析
QEMU CVE-2021-3947 和 CVE-2021-3929 漏洞利用分析 CVE-2021-3947 信息泄露漏洞 漏洞分析 漏洞点是 nvme_changed_nslist stati ...
- 使用 Autofac, MediatR 和 FluentValidator 构建松耦合 ASP.NET Core API 应用
使用 MediatR 和 FluentValidator 1. 创建示例文件夹 Sample 首先,创建示例文件夹 Sample. 2. 创建表示层项目 Web 在示例文件夹 Sample 中,使用标 ...
- Java JUC&多线程 基础完整版
Java JUC&多线程 基础完整版 目录 Java JUC&多线程 基础完整版 1. 多线程的第一种启动方式之继承Thread类 2.多线程的第二种启动方式之实现Runnable接口 ...
- 【网站搭建】开源社区Flarum搭建记录
环境 服务器系统:腾讯云 OpenCloudOS 宝塔版本:免费版8.0.1 Nginx:1.24.0 MySQL:5.7.42 PHP:8.1.21 萌狼蓝天 2023年8月7日 PHP设置 1.安 ...
- 深入理解二叉查找树(BST)的重要查找操作
二叉查找树 (Binary Search Tree, 简称 BST) 是一种基本的数据结构,其设计核心在于每个节点的值都满足以下性质: 左子树的所有节点值均小于当前节点值. 右子树的所有节点值均大于当 ...
- ArgoCD 简介
fork https://github.com/DevopsChina/lab/tree/main/deploy/lab04-argocd 1. ArgoCD 简介 基于 kubernetes 的声明 ...
- 一打开终端就默认进入conda的base环境,取消方法
conda版本:4.10.3 安装conda之后,在使用VSCode的时候,每次在里面使用powershell终端都是默认进入base环境,稍不注意就会用错python解释器,所以考虑取消这一设置.经 ...
- Qt音视频开发17-vlc内核回调拿图片进行绘制
一.前言 在众多播放器中,支持的种类格式众多,并支持DVD影音光盘,VCD影音光盘及各类流式协议,提供了sdk进行开发,这点是至关重要的,尽管很多优秀的播放器很牛逼,由于没有提供sdk第三方开发,少了 ...
- Qt编写地图综合应用13-获取边界点
一.前言 获取边界点一般和行政区划搭配起来使用,比如用户输入一个省市的名称,然后自动定位到该省市,然后对该轮廓获取所有边界点集合输出到js文件,最后供离线使用,获取边界点还有一个功能就是获取当前区域内 ...
- U盘或光盘启动的Win7-8-10的PE系统制作步骤
U盘或光盘启动的Win7-8-10的PE系统制作步骤 1.打开http://www.ushendu.com/下载PE制作工具 2.下载完成后安装到我的电脑, 把准备好的U盘插到电脑上,打开U深度PE制 ...