qt 取多个相同字符中间的字符串

#例如:
[A]123[B]
[A]321[B]
[A]456[B]
[A]654[B]
这样的数据QString数据我如何批量取[A][B]之间的字符串啊?

其实你的字符串首尾是固定的位数,就把首尾去掉三个字符就行了,这两句就能实现

s.remove(s.length() - 3, 3);
s.remove(0, 3);

补充:

去除行首指定字符(串)
使用left与remove接口

left(n)为从行首往后找n个字符;

remove(position, n), position为行中位置,n为删除的字符数量。

QString s = "testHello world!!!";
if (s.left(4) == "test")
    qDebug()<<s.remove(0, 4);

输出结果:
"Hello world!!!"

去除行尾指定字符(串)
.使用right与remove接口

right(n)为从行尾往前找n个字符;

remove(position, n), position为行中位置,n为删除的字符数量。

QString s = "Hello world!!!test";
if (s.right(4) == "test")
    qDebug()<<s.remove(s.length() - 4, 4);

输出结果:
"Hello world!!!"