Qt 字符串查找 字符串截断

el/2024/5/23 1:10:14

Qt 字符串查找


itstr.indexOf("xc")
itstr.indexOf("xc",itstr.indexOf("xc")+2)
itstr.lastIndexOf("xc")
itstr.indexOf(QRegExp("[0-9]+"));

字符串截断


itstr.chop(5);
itstr.left(itstr.indexOf("xc"));
itstr.right(itstr.size() - itstr.indexOf("xc") - 2);

字符串替换


itstr.replace("[name]","xiaoming");
itstr.replace(QRegExp("[0-9]"),"[NUM]");

#include <QApplication>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{QApplication a(argc, argv);QString str = "dsadsadsa.adsdada.[name],[id],[name],adas";for(int i = 0;i < str.size(); i++){cout<<str[i].toLatin1();}cout<<endl;QString::iterator itr = str.begin();for(;itr!=str.end();itr++){cout<<itr->toLatin1();}cout<<endl;QString key = "[name]";int pos = str.indexOf(key);cout<<"pos = "<<pos<<endl;int pos1 = str.indexOf(key,pos);cout<<"pos1 = "<<pos1<<endl;int pos2 = str.indexOf(key,pos1+key.size());cout<<"pos2 = "<<pos2<<endl;int pos3 = str.indexOf(key,pos2+key.size());cout<<"pos3 = "<<pos3<<endl;return 0;
//    return a.exec();
}

xz@xiaqiu:~/study/csdn/day0/winstate/build$ ./testqt 
dsadsadsa.adsdada.[name],[id],[name],adas
dsadsadsa.adsdada.[name],[id],[name],adas
pos = 18
pos1 = 18
pos2 = 30
pos3 = -1
xz@xiaqiu:~/study/csdn/day0/winstate/build$ 

#include <QApplication>
#include <QDebug>
int main(int argc, char *argv[])
{QString str = "dsadsadsa.adsdada.{[name],[id],[name]},adas";//str.chop(4);qDebug()<<str;//取第一个{括号之前int bpos = str.indexOf("{");int epos = str.lastIndexOf("}");str.left(bpos);qDebug()<<str.left(bpos);qDebug()<<str.right(str.size() - epos - 1);//取括号之间str.chop(str.size() - epos);qDebug()<<str;qDebug()<<str.right(epos - bpos - 1);QString str2 = "dsadsadsa.adsdada.{[name],[id],[name]},adas";//字符串替换str2.replace("[name]","xiaoming");qDebug()<<str2;//字符串切割QString str3 = "[name],[id],[name]";QStringList list1 = str3.split(",");for(int i = 0;i < list1.size();i++){qDebug()<<list1[i];}return 0;
}

xz@xiaqiu:~/study/csdn/day0/winstate/build$ ./testqt 
"dsadsadsa.adsdada.{[name],[id],[name]},adas"
"dsadsadsa.adsdada."
",adas"
"dsadsadsa.adsdada.{[name],[id],[name]"
"[name],[id],[name]"
"dsadsadsa.adsdada.{xiaoming,[id],xiaoming},adas"
"[name]"
"[id]"
"[name]"
xz@xiaqiu:~/study/csdn/day0/winstate/build$ 

http://www.ngui.cc/el/5239655.html

相关文章

QPushButton 样式设置 渐变圆角光泽按钮

QPushButton 1.事件设置 2.快捷键设置 3.样式设置 QPushButton事件信号 1.click() 2.click(bool) 是否选中 3.pressed() 4.released() #include <QWidget> #include <QDebug> QT_BEGIN_NAMESPACE namespace Ui { class Widget; } QT_END_NAMESPACEclass Widget :…

遍历所有QObject的子节点

遍历所有QObject的子节点 1.遍历子节点-获取节点对象的名称 2.QObjectList children() 3.objectName() 4.转换子节点-获取节点对象的类型 5.QMetaObject *metaObject() 6.metaObject()->className(); 7.qobject_cast<QCheckBox*>(cb); ui_widget.h #ifndef UI_WIDGET…

Qt - QRadioButton

QRadioButton 1.类似QCheckBox 2.默认单选 3.布局器 4.QButtonGroup获取选中的Button Widget.cpp #include "widget.h" #include "ui_widget.h" #include <QRadioButton> #include <QVBoxLayout> #include <QButtonGroup> #include <…

Qt事件Event

Qt事件Event 1.事件函数event 2.鼠标事件 3.键盘事件 4.窗口大小变化事件 5.重绘事件 重载event 1.bool event(QEvent *e); 2.返回true 处理下一个事件 3.返回false本事件的下一个处理函数QEvent子类 1.QKeyEvent,QMouseEvent 2.QTouchEvent,QWheelEvent QWidget重载函数 1.…

QPainter融合两张图片渲染

QPainter融合两张图片渲染 QPainter painter(this); out src.copy(); QPainter p(&out); p.setRenderHint(QPainter::Antialiasing); p.drawImage(0,0,img); p.end(); painter.drawImage(0,0,out); painter.end();XPS图片编辑器 1.打开存储图片(菜单) 2.画笔和橡皮 3.画笔…

ffmpeg rgb_to_mp4

视频编码 1.读取RGB文件转换为yuv 2.压缩为h264 3.封装为MP4 ffmpeg -i test.mp4 -pix_fmt bgra out.rgb av_interleaved_write_frame 1.AVFormatContext *s 2.AVPacket *pkt 3.按照dts排序 4.av_write_frame (缓冲处理dts)rgb_to_mp4.cpp extern "C" {#include &l…

音频采样率 wav->aac

音频采样率 1.采样率sample_rate 44100(CD) 2.通道channels (左右声道) 3.样本大小(格式) sample_size -AV_SAMPLE_FMT_S16 -AV_SAMPLE_FMT_FLTP wav_to_aac.cpp extern "C" {#include <libavformat/avformat.h>#include <libswscale/swscale.h>#inc…

ffmpeg 推流到 crtmpserver 测试

直播 rtmp 分发 退流------>直播服务器CDN------>各个客户端(rtmp,http-flv,hls) 推流 RGB RGB rtsp h264 1.图像采集----->美颜&#xff0c;水印—>转YUV H264编码 rtsp aac 2.音频采集----->去噪&#xff0c;变音—>音频重采样aac编码 PCM (h264 aac) --…

nginx rtmp

下载nginx wget http://nginx.org/download/nginx-1.21.4.tar.gz git clone https://github.com/arut/nginx-rtmp-module.git安装 libpcre3-dev sudo apt install libpcre3-dev./configure --add-module/home/xz/study/csdn/rtmp/nginx/nginx-rtmp-module xzxiaqiu:~/study/csd…

opencv打开摄像头ffmpeg推流到nginx-rtmp

基于opencv采集推流 1.opencv采集rtsp解码 //可以基于usb 摄像机(调用系统驱动)和rtsp(调用ffmpeg 接口 转yuv加解码) 摄像机 2.ffmpeg缩放转换像素格式 3.ffmpeg编码H264 4.ffmpeg推流rtmp sws_getCachedContext (像素格式转换 会清理之前的数据) 1.struct SwsContext *cont…