16,213
社区成员
发帖
与我相关
我的任务
分享
QString str="asda asdasdaA b";
str.replace(QRegExp("([A-Z]) +([a-z])"),"\\1 \\2");
试试这个代码
你在Qtcreator进一下QString::relpace的文档可以看到如下说明:
QString &QString::replace(const QRegularExpression &re, const QString &after)
This function overloads replace().
Replaces every occurrence of the regular expression re in the string with after. Returns a reference to the string. For example:
QString s = "Banana";
s.replace(QRegularExpression("a[mn]"), "ox");
// s == "Boxoxa"
For regular expressions containing capturing groups, occurrences of \1, \2, ..., in after are replaced with the string captured by the corresponding capturing group.
QString t = "A <i>bon mot</i>.";
t.replace(QRegularExpression("<i>([^<]*)</i>"), "\\emph{\\1}");
// t == "A \\emph{bon mot}."
This function was introduced in Qt 5.0.