雷火电竞-中国电竞赛事及体育赛事平台

歡迎來(lái)到入門教程網(wǎng)!

C語(yǔ)言

當(dāng)前位置:主頁(yè) > 軟件編程 > C語(yǔ)言 >

QString使用正則操作的接口實(shí)現(xiàn)

來(lái)源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C語(yǔ)言|點(diǎn)擊:

介紹QString使用正則操作的接口。

Qt 5.0引入QRegularExpression,相比于QRegExp,前者修復(fù)了很多bugs,功能上也是兼容于QRegExp。推薦使用QRegularExpression。

contains

正則表達(dá)式rx是否與字符串中的某個(gè)地方匹配,匹配返回true,否則返回false。

bool contains(const QRegExp &rx) const
bool contains(QRegExp &rx) const
bool contains(const QRegularExpression &re) const
bool contains(const QRegularExpression &re, QRegularExpressionMatch *match) const

count

返回正則表達(dá)式rx在字符串中匹配的次數(shù)。

int count(const QRegExp &rx) const
int count(const QRegularExpression &re) const

indexOf

返回字符串中正則表達(dá)式rx的第一個(gè)匹配項(xiàng)的索引位置,從索引位置向前搜索。如果rx在任何地方都不匹配,則返回-1。

int indexOf(QRegExp &rx, int from = 0) const
int indexOf(const QRegularExpression &re, int from = 0) const
int indexOf(const QRegularExpression &re, int from, QRegularExpressionMatch *rmatch) const

lastIndexOf

返回字符串中正則表達(dá)式rx最后一個(gè)匹配項(xiàng)的索引位置,從索引位置向后搜索。如果rx在任何地方都不匹配,則返回-1。

int lastIndexOf(QRegExp &rx, int from = -1) const
int lastIndexOf(const QRegularExpression &re, int from = -1) const
int lastIndexOf(const QRegularExpression &re, int from, QRegularExpressionMatch *rmatch) const

remove

移除字符串中符合正則表達(dá)式rx的匹配,并返回對(duì)該字符串的引用。

QString &remove(const QRegExp &rx)
QString &remove(const QRegularExpression &re)

replace

將字符串中符合正則表達(dá)式rx就替換為after字符串,并返回對(duì)該字符串的引用。

QString &replace(const QRegExp &rx, const QString &after)
QString &replace(const QRegularExpression &re, const QString &after)

section

將字符串由正則表達(dá)式來(lái)分割字段序列。

QString section(const QRegExp ®, int start, int end = -1, QString::SectionFlags flags = SectionDefault) const
QString section(const QRegularExpression &re, int start, int end = -1, QString::SectionFlags flags = SectionDefault) const

split

將字符串拆分為正則表達(dá)式rx匹配的子字符串,并返回這些字符串的列表。

QStringList split(const QRegExp &rx, QString::SplitBehavior behavior = KeepEmptyParts) const
QStringList split(const QRegularExpression &re, QString::SplitBehavior behavior = KeepEmptyParts) const

splitRef

將字符串拆分為正則表達(dá)式rx匹配的子字符串引用,并返回這些字符串的列表。

QVector<QStringRef> splitRef(const QRegExp &rx, QString::SplitBehavior behavior = KeepEmptyParts) const
QVector<QStringRef> splitRef(const QRegularExpression &re, QString::SplitBehavior behavior = KeepEmptyParts) const

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。

上一篇:opencv3/C++輪廓的提取與篩選方式

欄    目:C語(yǔ)言

下一篇:opencv3/C++ 直方圖反向投影實(shí)例

本文標(biāo)題:QString使用正則操作的接口實(shí)現(xiàn)

本文地址:http://www.jygsgssxh.com/a1/Cyuyan/102.html

網(wǎng)頁(yè)制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語(yǔ)言數(shù)據(jù)庫(kù)服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有