1、indexOf
#define GID_PREFIX "dr_" QString str = "dr__awedr4"; int iIdx = str.indexOf(GID_PREFIX); qDebug() << iIdx; str = "awedr4"; iIdx = str.indexOf(GID_PREFIX); qDebug() << iIdx; str = "awedr_4"; iIdx = str.indexOf(GID_PREFIX); qDebug() << iIdx;
2、控制台输出
0 -1 3
3、mid
#define GID_PREFIX "dr_" QString str = "dr__awedr4"; QString str1; int iLen_prefix = strlen(GID_PREFIX); int iLen_Left = str.length() - iLen_prefix; qDebug() << iLen_Left; str1 = str.mid(iLen_prefix, iLen_Left); qDebug() << str1; str1 = str.mid(iLen_prefix); qDebug() << str1;
4、控制台输出
7 "_awedr4" "_awedr4"
5、