一,获取字符在字符串中的位置
<1>获取指定字符对应的位置
QString str = "AT+LOC+LOCATION: 115.850441,33.004833";
QString s = "LOC";
str.indexOf(s); //3
str.indexOf(s, 6); //7
<2>获取最后一个匹配的字符对应的位置
QString str = "AT+LOC+LOCATION";
QString s = "O";
str.lastIndexOf(s); //13
二,获取指定位置的字符串
QString str = "AT+LOC+LOCATION: 115.850441,33.004833";
QString s = str.mid(6); //"+LOCATION: 115.850441,33.004833"
QString s = str.mid(6, 9); //"+LOCATION"
三,根据对应字符,分割字符串
QString str = "AT+LOC+LOCATION";
QStringList list = str.split("+");
for(int i = 0; i < list.count(); i++)
{
qDebug() << list.at(i);
}
/