From 4a280d42f6920fedcbb4556c9a28aa1fc599116b Mon Sep 17 00:00:00 2001 From: "touwoyimuli@gmail.com" Date: Sun, 18 Aug 2019 20:13:28 +0800 Subject: [PATCH] QtQStringFunEx update QtQStringFunEx --- QtQStringFunEx/ExQStringFun.cpp | 198 +++++++++ QtQStringFunEx/ExQStringFun.h | 60 +++ QtQStringFunEx/ExQStringFun.ui | 686 ++++++++++++++++++++++++++++++ QtQStringFunEx/QT_win_32x32.ico | Bin 0 -> 4286 bytes QtQStringFunEx/QtQStringFunEx.pro | 42 ++ QtQStringFunEx/main.cpp | 11 + 6 files changed, 997 insertions(+) create mode 100644 QtQStringFunEx/ExQStringFun.cpp create mode 100644 QtQStringFunEx/ExQStringFun.h create mode 100644 QtQStringFunEx/ExQStringFun.ui create mode 100644 QtQStringFunEx/QT_win_32x32.ico create mode 100644 QtQStringFunEx/QtQStringFunEx.pro create mode 100644 QtQStringFunEx/main.cpp diff --git a/QtQStringFunEx/ExQStringFun.cpp b/QtQStringFunEx/ExQStringFun.cpp new file mode 100644 index 0000000..184a722 --- /dev/null +++ b/QtQStringFunEx/ExQStringFun.cpp @@ -0,0 +1,198 @@ +#include "ExQStringFun.h" +#include "ui_ExQStringFun.h" + +ExQStringFun::ExQStringFun(QWidget* parent) : + QWidget(parent), + ui(new Ui::ExQStringFun) +{ + ui->setupUi(this); +} + +ExQStringFun::~ExQStringFun() +{ + delete ui; +} + +//字符串相关 +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +void ExQStringFun::on_btnAppend_clicked() +{ + QString str1 = ui->comboxStr1->currentText(); + QString str2 = ui->comboxStr2->currentText(); + str1.append(str2); + ui->editResult->setText(str1); +} + +void ExQStringFun::on_btnPrepend_clicked() +{ + QString str1 = ui->comboxStr1->currentText(); + QString str2 = ui->comboxStr2->currentText(); + str1.prepend(str2); + ui->editResult->setText(str1); +} + +void ExQStringFun::on_btnToUpper_clicked() +{ + QString str1 = ui->comboxStr1->currentText(); + QString strRet = str1.toUpper(); + ui->editResult->setText(strRet); +} + +void ExQStringFun::on_btnToLower_clicked() +{ + QString str1 = ui->comboxStr1->currentText(); + QString strRet = str1.toLower(); + ui->editResult->setText(strRet); +} + +void ExQStringFun::on_btnLeft_clicked() +{ + QString str1 = ui->comboxStr1->currentText(); + int n = ui->spinLabSpin->value(); + QString strRet = str1.left(n); + ui->editResult->setText(strRet); + +} + +void ExQStringFun::on_btnRight_clicked() +{ + QString str1 = ui->comboxStr1->currentText(); + int n = ui->spinLabSpin->value(); + QString strRet = str1.right(n); + ui->editResult->setText(strRet); +} + +void ExQStringFun::on_btnSection_clicked() +{ + QString str1 = ui->comboxStr1->currentText(); + QString str2 = ui->comboxStr2->currentText(); + int n = ui->spinLabSpin->value(); + + QString str3 = str1.section(str2, n, n+1); + ui->editResult->setText(str3); +} + +void ExQStringFun::on_btnSimplified_clicked() +{ + QString str1 = ui->comboxStr1->currentText(); + QString strRet = str1.simplified(); + ui->editResult->setText(strRet); +} + +void ExQStringFun::on_btnTrimmed_clicked() +{ + QString str1 = ui->comboxStr1->currentText(); + QString strRet = str1.trimmed(); + ui->editResult->setText(strRet); +} + +//数字相关 +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +void ExQStringFun::on_btnCount_clicked() +{ + QString str1 = ui->comboxStr1->currentText(); + QString strRet = QString("count():%1").arg(str1.count()); + ui->editResult->setText(strRet); +} + +void ExQStringFun::on_btnSize_clicked() +{ + QString str1 = ui->comboxStr1->currentText(); + QString strRet = QString("size():%1").arg(str1.size()); + ui->editResult->setText(strRet); +} + +void ExQStringFun::on_btnIndexOf_clicked() +{ + QString str1 = ui->comboxStr1->currentText(); + QString str2 = ui->comboxStr2->currentText(); + + QString strRet = QString("IndexOf():%1").arg(str1.indexOf(str2)); + ui->editResult->setText(strRet); +} + + +void ExQStringFun::on_btnLastIndexOf_clicked() +{ + QString str1 = ui->comboxStr1->currentText(); + QString str2 = ui->comboxStr2->currentText(); + + QString strRet = QString("lastIndexOf():%1").arg(str1.lastIndexOf(str2)); + ui->editResult->setText(strRet); +} + +//逻辑判断相关 +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +void ExQStringFun::on_btnStartsWith_clicked() +{ + QString str1 = ui->comboxStr1->currentText(); + QString str2 = ui->comboxStr2->currentText(); + QString str3 = ""; + + if (str1.startsWith(str2)) + str3 = "str1是以str2字符串开头"; + else + str3 = "str1不是以str2字符串开头"; + + QString strRet = QString("startsWith():%1").arg(str3); + ui->editResult->setText(strRet); +} + +void ExQStringFun::on_btnEndsWith_clicked() +{ + QString str1 = ui->comboxStr1->currentText(); + QString str2 = ui->comboxStr2->currentText(); + QString str3 = ""; + + if (str1.endsWith(str2)) + str3 = "str1是以str2字符串结尾"; + else + str3 = "str1不是以str2字符串结尾"; + + QString strRet = QString("endsWith():%1").arg(str3); + ui->editResult->setText(strRet); +} + +void ExQStringFun::on_btnContains_clicked() +{ + QString str1 = ui->comboxStr1->currentText(); + QString str2 = ui->comboxStr2->currentText(); + QString str3 = ""; + + if (str1.contains(str2)) + str3 = "str1字符中包含str2字符串"; + else + str3 = "str1字符中不包含str2字符串"; + + QString strRet = QString("contains():%1").arg(str3); + ui->editResult->setText(strRet); +} + +void ExQStringFun::on_btnIsNull_clicked() +{ + QString str1 = ui->comboxStr1->currentText(); + QString str = "未赋值"; + + if(str1.isNull()) + str = "true"; + else + str = "false"; + + QString strRet = QString("str1.isNull() => %1").arg(str); + ui->editResult->setText(strRet); +} + +void ExQStringFun::on_btnIsEmpty_clicked() +{ + QString str1 = ui->comboxStr1->currentText(); + QString str = "未赋值"; + + if(str1.isNull()) + str = "true"; + else + str = "false"; + + QString strRet = QString("str1.isEmpty() => %1").arg(str); + ui->editResult->setText(strRet); +} diff --git a/QtQStringFunEx/ExQStringFun.h b/QtQStringFunEx/ExQStringFun.h new file mode 100644 index 0000000..e33499f --- /dev/null +++ b/QtQStringFunEx/ExQStringFun.h @@ -0,0 +1,60 @@ +#ifndef EXQSTRINGFUN_H +#define EXQSTRINGFUN_H + +#include + +namespace Ui { +class ExQStringFun; +} + +class ExQStringFun : public QWidget +{ + Q_OBJECT + +public: + explicit ExQStringFun(QWidget *parent = nullptr); + ~ExQStringFun(); + +private slots: + void on_btnAppend_clicked(); + + void on_btnPrepend_clicked(); + + void on_btnToUpper_clicked(); + + void on_btnToLower_clicked(); + + void on_btnLeft_clicked(); + + void on_btnRight_clicked(); + + void on_btnSection_clicked(); + + void on_btnSimplified_clicked(); + + void on_btnTrimmed_clicked(); + + void on_btnCount_clicked(); + + void on_btnSize_clicked(); + + void on_btnIndexOf_clicked(); + + + void on_btnLastIndexOf_clicked(); + + void on_btnStartsWith_clicked(); + + void on_btnEndsWith_clicked(); + + void on_btnContains_clicked(); + + void on_btnIsNull_clicked(); + + void on_btnIsEmpty_clicked(); + +private: + Ui::ExQStringFun *ui; +}; + +#endif // EXQSTRINGFUN_H diff --git a/QtQStringFunEx/ExQStringFun.ui b/QtQStringFunEx/ExQStringFun.ui new file mode 100644 index 0000000..92deb3d --- /dev/null +++ b/QtQStringFunEx/ExQStringFun.ui @@ -0,0 +1,686 @@ + + + ExQStringFun + + + + 0 + 0 + 675 + 865 + + + + ExQStringFun + + + + + + + + + + + 100 + 16777215 + + + + CheckBox + + + + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 60 + 20 + + + + + + + + + 16777215 + 16777215 + + + + left(int n)和right(int n)、section()函数使用,输入参数: + + + + + + + + 120 + 16777215 + + + + 3 + + + + + + + + + true + + + true + + + D:\programming\qt\QtExamples\QtQStringFunEx\main.cpp + + + + D:\programming\qt\QtExamples\QtQStringFunEx\main.cpp + + + + + D:\programming\qt\QtExamples\QtQStringFunEx + + + + + 投我以木李,报之以琼玖, 男,1998-07-07,汉族,湖北, 武汉 + + + + + csdn:https://blog.csdn.net/qq_33154343 + + + + + github:https://github.com/touwoyimuli + + + + + github.io:https://touwoyimuli.github.io/ + + + + + 或者自己自定义更多 + + + + + + + + + 0 + 0 + + + + + 50 + 20 + + + + + 75 + true + + + + str2: + + + + + + + true + + + true + + + \ + + + + \ + + + + + .cpp + + + + + : + + + + + + + + + + 或自定义更多尝试 + + + + + + + + + 50 + 20 + + + + + 75 + true + + + + str1: + + + + + + + + 75 + true + + + + 结果: + + + + + + + + + + ↓↓ + + + Qt::AlignCenter + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 10 + + + + + + + + QString常用函数 + + + + + + + + + + + 0 + 20 + + + + + 75 + true + + + + 字符串相关: + + + + + + + perpend() + + + + + + + + 120 + 16777215 + + + + + 50 + false + + + + append() + + + + + + + 在字符串后面添加字符串 + + + + + + + right() + + + + + + + section + + + + + + + 从字符串中提取以“子字符串”作为分隔符,从start到end端的字符串 + + + + + + + trimmed + + + + + + + 不仅去掉字符串的所首尾空格,中间连续的空格也用一个空格替换 + + + + + + + 返回包含字符串中最右n个字符的子字符串。如果n大于或等于size()或小于零,则返回整个字符串。 + + + + + + + simplified + + + + + + + 去掉字符串首尾的空格 + + + + + + + 在字符串的前面添加字符串 + + + + + + + toUpper() + + + + + + + 将字符串的字母全部转换为大写字母 + + + + + + + 返回包含字符串中最左n个字符的子字符串。如果n大于或等于size()或小于零,则返回整个字符串。 + + + + + + + 将字符串的字母全部转换为大写字母 + + + + + + + toLower() + + + + + + + left() + + + + + + + + + Qt::Horizontal + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 10 + + + + + + + + + + size + + + + + + + 同上 + + + + + + + 在字符串中查找子字符串str出现的位置。(Qt::CaseSensitivity cs 参数指定是否区分大小写) + + + + + + + indexOf + + + + + + + + 120 + 16777215 + + + + count + + + + + + + 在字符串中查找子字符串str最后出现的位置 + + + + + + + lastIndexOf + + + + + + + 返回字符串的字符个数。函数同size()、同length()。(字符串中若有汉字,一个汉字算一个字符) + + + + + + + + 0 + 20 + + + + + 16777215 + 30 + + + + + 75 + true + + + + 数字相关: + + + + + + + + + Qt::Horizontal + + + + + + + + + + 0 + 20 + + + + + 16777215 + 30 + + + + + 75 + true + + + + 逻辑判断: + + + + + + + 判断是否以某个字符串开头 + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 10 + + + + + + + + endsWith + + + + + + + 判断是否以某个字符串结尾 + + + + + + + contains + + + + + + + 判断字符串是否为空。(若是只有“\0”,isNull返回false; 只有未赋值的字符串,isNull返回true) + + + + + + + 判断某个字符串中是否包含某个字符串 + + + + + + + isNull + + + + + + + isEmpty + + + + + + + + 120 + 16777215 + + + + startsWith + + + + + + + 判断字符串是否为空.(若是只有“\0”,isEmpty返回true) + + + + + + + + 75 + true + + + + 注意:QString只要赋值,就在字符串的末尾自动加上“\0” + + + + + + + + + + + + + + + + diff --git a/QtQStringFunEx/QT_win_32x32.ico b/QtQStringFunEx/QT_win_32x32.ico new file mode 100644 index 0000000000000000000000000000000000000000..0ee0568945377c30d5d973d89afcc31770cd8818 GIT binary patch literal 4286 zcmeHKdr(y86+io87ZyYwA_hySrjx{)Njo~7w3D=Go0O&*)2xbtP|_lTj{v^F6l<|4 z!TRE16coi*F_>DPiHV~$YSL&Lgk=|&m4~p)V}S)!47%0a{(A22URjA+|FAR3OzzI_ zp6@&7JHKBO?Lu5#%-ZBiRg$@WRi6TzUI$u#k!Uz4@+6%sBmDt|-5nU_e| z7fHeg@p7SVjknOZZ=`Vjy7MivgQDE}G#O0Oe_VLG8&NBA&`P!TV~z&n1pb#e?G?}cIT z&=`F2_fRJW4~F8#u}5(8_!tb9kHklFz0kAS7lZplFi;kZfgNhJq$t6h5IOG!{VQ~X z2S8Ikg_Bh8jEmPp%hXZkq`TBPS!M-yb_T3X;-}6Hkc0Gxn(s1;a2I2DF zQMg(b%I!v@XIn5j-}YnqC>qnhiyATZjC(_j`NC+@{_Pi}tBIyBD_$a)m&h4GCPW}OX$I{VzbSW->umrt_;?Pqz6}FObux$xM$Ce*qcgVDYBr!b^G2IH$T7-M9pWr$KL5339F zo}z&LQ50A4GT};|0`{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K7v~YuONd%(^LTxixQeZe@xV5SUH(7$yHwU9E_`fj_S-voQd_h?I-zHrnpw?2gij z-{EgC0{=xY#Za*^hECprSzMPO*`&Ise3j1C#?pU`vAp+V`TP@Qj9B)BThF@M7+NdF zeV9*ulDwM1catZ?yUJY`?;tLlljN7h{yxmuB3Da>s;D`G&#eD}mJH?ThaFqwtIZ;> z_H5PDEm^7`+z-vm$p8Nl|69&)<_KWevy%75gMfQ0?xEpe)zGt&?Wg%a9&lRi!mwam F{Vzx7jH3Vm literal 0 HcmV?d00001 diff --git a/QtQStringFunEx/QtQStringFunEx.pro b/QtQStringFunEx/QtQStringFunEx.pro new file mode 100644 index 0000000..3d5b7ff --- /dev/null +++ b/QtQStringFunEx/QtQStringFunEx.pro @@ -0,0 +1,42 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2019-08-18T14:08:16 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = QtQStringFunEx +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +CONFIG += c++11 + +SOURCES += \ + main.cpp \ + ExQStringFun.cpp + +HEADERS += \ + ExQStringFun.h + +FORMS += \ + ExQStringFun.ui + +RC_ICONS += QT_win_32x32.ico + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/QtQStringFunEx/main.cpp b/QtQStringFunEx/main.cpp new file mode 100644 index 0000000..b235fd9 --- /dev/null +++ b/QtQStringFunEx/main.cpp @@ -0,0 +1,11 @@ +#include "ExQStringFun.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + ExQStringFun w; + w.show(); + + return a.exec(); +}