int QString::indexOf ( const QString & str, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
Returns the index position of the first occurrence of the string str in this string, searching forward from index position from. Returns -1 if str is not found.
If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
Example:
QString x = "sticky question";
QString y = "sti";
x.indexOf(y); // returns 0
x.indexOf(y, 1); // returns 10
x.indexOf(y, 10); // returns 10
x.indexOf(y, 11); // returns -1
If from is -1, the search starts at the last character; if it is -2, at the next to last character and so on.
本文详细介绍了QString类中的indexOf方法,该方法用于查找指定字符串首次出现的位置。文章通过示例展示了如何使用此方法,并解释了参数的意义及返回值的含义。
2572

被折叠的 条评论
为什么被折叠?



