原型
QString QString::mid(int position, int n = -1) const
Returns a string that contains n characters of this string, starting
at the specified position index. Returns a null string if the position
index exceeds the length of the string. If there are less than n
characters available in the string starting at the given position, or
if n is -1 (default), the function returns all characters that are
available from the specified position.
例子:
若需要QStringRef类型的子串,可以使用函数midRef (),与mid()类似,只是返回类型为ref,原型如下
QStringRef QString::midRef(int position, int n = -1) const
Returns a substring reference to n characters of this string, starting
at the specified position. If the position exceeds the length of the
string, a null reference is returned. If there are less than n
characters available in the string, starting at the given position, or
if n is -1 (default), the function returns all characters from the
specified position onwards.
Example:
QString 还有left() 和 right().两个函数可以取子串
原型
QString QString::left(int n) const
返回最左边n个字符的子串。当n大于等于QString.size()或n小于0的时候,返回整个字符串。
Returns a substring that contains the n leftmost characters of the
string. The entire string is returned if n is greater than or equal to
size(), or less than zero.
例子:
right()与left()类似,不阐述
版权声明:
本文来源网络,所有图片文章版权属于原作者,如有侵权,联系删除。
本文网址:https://www.mushiming.com/mjsbk/13734.html