【Qt笔记】[帮助文档]——类QString:取子串函数mid()、left()、right() ——QT怎么取字符串子串切片
mid()函数
原型
QString QString::mid(int position, int n = -1) const
返回一个从position开始,长度为n的QString 类型的子串。
当position的下标值超出字符串长度时,返回null;当从position开始的子串长度不够n或n为-1(缺省时的默认值也为-1),函数返回从position开始到结尾的子串。
Returns a string that contains n characters of this string, starting
at the specified position index. Returns a null string if the position
index exceeds the length of the string. If there are less than n
characters available in the string starting at the given position, or
if n is -1 (default), the function returns all characters that are
available from the specified position.
例子:
QString x = "Nine pineapples";QString y = x.mid(5, 4); // y == "pine"QString z = x.mid(5); // z == "pineapples"
midRef()
若需要QStringRef类型的子串,可以使用函数midRef (),与mid()类似,只是返回类型为ref,原型如下
QStringRef QString::midRef(int position, int n = -1) const
返回一个从position开始,长度为n的类型的子串的引用。
当position的下标值超出字符串长度时,返回null引用;当从position开始的子串长度不够n或n为-1(缺省时的默认值也为-1),函数返回从position开始直到结尾的子串。
Returns a substring reference to n characters of this string, starting
at the specified position. If the position exceeds the length of the
string, a null reference is returned. If there are less than n
characters available in the string, starting at the given position, or
if n is -1 (default), the function returns all characters from the
specified position onwards.
Example:
QString x = "Nine pineapples";QStringRef y = x.midRef(5, 4); // y == "pine"QStringRef z = x.midRef(5); // z == "pineapples"
QString 还有left() 和 right().两个函数可以取子串
left() 与 right()
原型
QString QString::left(int n) const
返回最左边n个字符的子串。当n大于等于QString.size()或n小于0的时候,返回整个字符串。
Returns a substring that contains the n leftmost characters of the
string. The entire string is returned if n is greater than or equal to
size(), or less than zero.
例子:
QString x = "Pineapple";QString y = x.left(4); // y == "Pine"
right()与left()类似,不阐述
【Qt笔记】[帮助文档]——类QString:取子串函数mid()、left()、right() ——QT怎么取字符串子串切片相关推荐
- QT读取Word文档
Word文档读取 开发工具与关键技术:QtCreator.C++ 作者:何任贤 撰写时间:2020年06月02日 Word文档读取 我们先要在工程文件加入 QT += axcontainer 我们要用 ...
- 使用Qt创建XML文档及XML文档的增删改
目录名字 使用Qt创建XML文档及XML文档的增删改 XML文档的操作 :QXml + QFile+QTextStream 创建XML的一般步骤: XML 文档的操作(添加.查找.更新.删除) 添加的 ...
- QT 生成word文档
这篇文章在原博客上加上了一些原博主没有写出的一些细节访问的东西,(间接抄袭.......) 原博客 :http://blog.csdn.net/zhangfuliang123/article/deta ...
- Qt 读取XML文档的简单示例
目录名字 XML简介 Qt 操作XML文档一般方法 使用DOM读取XML文档 示例代码:读取XML文档 XML简介 XML(Extensible Markup Language,可扩展标记语言)是一种 ...
- Manim文档及源码笔记-CE文档-示例库3使用Manim绘图
Manim文档及源码笔记-CE文档-示例库3使用Manim绘图 参考原文: Manim Community Edition Example Gallery 前言 笔记随想: 暂未发现官方中文版,自己实 ...
- Qt对word文档操作总结
Qt对word文档操作总结 近期在使用Qt对word进行读写操作时候遇到很多问题,对于Qt内部没有很好的库函数可以使用.office官网上的文档只有VBA的示例,没有Qt的语法例子.在这里作者介绍了一 ...
- Qt写一个文档复制粘贴助手app
Qt写一个文档复制粘贴助手app 环境如下 创建工程 打开Qt Creater 7.0.0(community) 下载安装环境的自行百度吧 我们点击文件-> New Project ->然 ...
- 【排版软件系列】 LaTeX文档类 Beamer
Beamer是一个LaTeX文档类,用于为演示文稿创建幻灯片.它支持pdfLaTeX和LaTeX + dvips,不支持Latex+dvipdfm Beamer - 用于制作演示文稿的LaTeX类 概 ...
- QT/C++标签文档报表工具
QT/C++标签文档报表工具 一.演示预览 二.使用步骤 1.环境配置 二.核心代码 1.报表程序 2. 数据库程序 三.代码链接 一.演示预览 二.使用步骤 1.环境配置 1.第一次在电脑上需要注册 ...
最新文章
- 英伟达TensorRT 8-bit Inference推理
- P1486 [NOI2004] 郁闷的出纳员 FHQ-Treap
- [YTU]_2866(结构体---点坐标结构体)
- 简明python教程 --C++程序员的视角(八):标准库
- cacti + nagios + npc 整合部署
- EBS模块介绍和概念解释
- python map函数返回类型_使用map和lambda函数发送两个参数并返回两个值
- 函数返回结构体指针_9.3 结构体指针
- 如何做一个国产数据库系统(一)
- 我的cocos2d-x集成sharesdk之旅(转)
- Visio2019异步消息箭头线使用问题
- 教你开发一个JS代码加密工具
- 移动硬盘插入提示需要格式化RAW_内存卡无法格式化解决办法
- C#中DataTime.Now函数详解
- dns解析失败故障问题解决两例
- 17家中国初创IT公司的失败史
- 嵊州D4T1 翻车 rollover 真的翻车了
- 昆山python线下培训班,苏州昆山有没有python培训班(会python的好处)
- presto安装问题
- android自动刷广告软件是,android开发通过辅助服务实现自动刷抖音极速版赚金币。。。。...