Qt 字串擷取 獲取指定字元位置
阿新 • • 發佈:2018-12-12
獲取字元在字串中的位置
QString str = "AT+LOC+LOCATION: 115.850441,33.004833";
QString s = "LOC";
str.indexOf(s); //3
str.indexOf(s, 6); //7
擷取指定位置字元
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 url = "https://www.baidu.com"; if(url.startsWith("https") && url.endsWith("com")) //true //等價於 if(url.left(5) == "https" && url.right(3) == "com") //true
是否包含字串
QString str = "AT+LOC+LOCATION: 115.850441,33.004833";
if(str.contains("LOC", Qt::CaseSensitive)) //true
--------------------- 本文來自 thomas_blog 的CSDN 部落格 ,全文地址請點選:https://blog.csdn.net/zhangxuechao_/article/details/81700266?utm_source=copy