关于QString中的字符匹配问题纠结了我半天时间,终于搞定了,分享一下的我的经验吧!
1.获取QString中匹配字符串的数量
int num = 0;//匹配字符串的数量
while(ui->textEdit->find(str)){
num++;
}
其中str为匹配的字符串,num为最后的匹配数量</span>
2.获取QString中匹配字符串中第一个的位置和最后一个位置
int num_first = text.indexOf(str);//匹配文本的第一个的位置
int num_last = text.lastIndexOf(str);//匹配文本的最后一个的位置
其中exp是匹配的字符串,num为匹配的数量