QStringRef 類提供的瘦包裹器圍繞 QString 子字符串。 更多...
| 頭: |
#include <QStringRef>
|
| CMake: |
find_package(Qt6 REQUIRED COMPONENTS Core5Compat)
target_link_libraries(mytarget PRIVATE Qt6::Core5Compat)
|
| qmake: |
QT += core5compat
|
注意: 此類的所有函數 可重入 .
| const_iterator | |
| const_reverse_iterator |
| QStringRef () | |
| QStringRef (const QString * string ) | |
| QStringRef (const QString * string , int position , int length ) | |
| QStringRef (const QStringRef & other ) | |
| ~QStringRef () | |
| QStringRef | appendTo (QString * string ) const |
| const QChar | at (int position ) const |
| QChar | back () const |
| QStringRef::const_iterator | begin () const |
| QStringRef::const_iterator | cbegin () const |
| QStringRef::const_iterator | cend () const |
| void | chop (int n ) |
| QStringRef | chopped (int len ) const |
| void | clear () |
| int | compare (QChar ch , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| int | compare (QLatin1String other , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| int | compare (const QByteArray & other , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| int | compare (const QString & other , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| int | compare (const QStringRef & other , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| QStringRef::const_iterator | constBegin () const |
| const QChar * | constData () const |
| QStringRef::const_iterator | constEnd () const |
| bool | contains (const QString & str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | contains (QChar ch , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | contains (QLatin1String str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | contains (QStringView str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | contains (const QStringRef & str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| int | count () const |
| int | count (const QString & str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| int | count (QChar ch , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| int | count (const QStringRef & str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| QStringRef::const_reverse_iterator | crbegin () const |
| QStringRef::const_reverse_iterator | crend () const |
| const QChar * | data () const |
| QStringRef::const_iterator | end () const |
| bool | endsWith (const QString & str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | endsWith (QChar ch , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | endsWith (QLatin1String str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | endsWith (QStringView str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | endsWith (const QStringRef & str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| QChar | front () const |
| int | indexOf (QLatin1String str , int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| int | indexOf (const QString & str , int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| int | indexOf (QChar ch , int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| int | indexOf (QStringView str , int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| int | indexOf (const QStringRef & str , int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | isEmpty () const |
| bool | isNull () const |
| bool | isRightToLeft () const |
| int | lastIndexOf (const QString & str , int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| int | lastIndexOf (QChar ch , int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| int | lastIndexOf (QLatin1String str , int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| int | lastIndexOf (QStringView str , int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| int | lastIndexOf (const QStringRef & str , int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| QStringRef | left (int n ) const |
| int | length () const |
| int | localeAwareCompare (const QString & other ) const |
| int | localeAwareCompare (const QStringRef & other ) const |
| QStringRef | mid (int position , int n = -1) const |
| int | position () const |
| QStringRef::const_reverse_iterator | rbegin () const |
| QStringRef::const_reverse_iterator | rend () const |
| QStringRef | right (int n ) const |
| int | size () const |
| QList<QStringRef> | split (const QString & sep , Qt::SplitBehavior behavior = Qt::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| QList<QStringRef> | split (QChar sep , Qt::SplitBehavior behavior = Qt::KeepEmptyParts, Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | startsWith (const QString & str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | startsWith (QChar ch , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | startsWith (QLatin1String str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | startsWith (QStringView str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| bool | startsWith (const QStringRef & str , Qt::CaseSensitivity cs = Qt::CaseSensitive) const |
| const QString * | string () const |
| double | toDouble (bool * ok = nullptr) const |
| float | toFloat (bool * ok = nullptr) const |
| int | toInt (bool * ok = nullptr, int base = 10) const |
| QByteArray | toLatin1 () const |
| QByteArray | toLocal8Bit () const |
| long | toLong (bool * ok = nullptr, int base = 10) const |
| qlonglong | toLongLong (bool * ok = nullptr, int base = 10) const |
| short | toShort (bool * ok = nullptr, int base = 10) const |
| QString | toString () const |
| uint | toUInt (bool * ok = nullptr, int base = 10) const |
| ulong | toULong (bool * ok = nullptr, int base = 10) const |
| qulonglong | toULongLong (bool * ok = nullptr, int base = 10) const |
| ushort | toUShort (bool * ok = nullptr, int base = 10) const |
| QList<uint> | toUcs4 () const |
| QByteArray | toUtf8 () const |
| QStringRef | trimmed () const |
| void | truncate (int position ) |
| const QChar * | unicode () const |
| bool | operator!= (const char * s ) const |
| bool | operator< (const char * s ) const |
| bool | operator<= (const char * s ) const |
| QStringRef & | operator= (const QString * string ) |
| QStringRef & | operator= (const QStringRef & other ) |
| bool | operator== (const char * s ) const |
| bool | operator> (const char * s ) const |
| bool | operator>= (const char * s ) const |
| QChar | operator[] (int position ) const |
| int | compare (const QStringRef & s1 , const QString & s2 , Qt::CaseSensitivity cs = Qt::CaseSensitive) |
| int | compare (const QStringRef & s1 , QLatin1String s2 , Qt::CaseSensitivity cs = Qt::CaseSensitive) |
| int | compare (const QStringRef & s1 , const QStringRef & s2 , Qt::CaseSensitivity cs = Qt::CaseSensitive) |
| int | localeAwareCompare (const QStringRef & s1 , const QString & s2 ) |
| int | localeAwareCompare (const QStringRef & s1 , const QStringRef & s2 ) |
| bool | operator< (const QStringRef & s1 , const QStringRef & s2 ) |
| bool | operator<= (const QStringRef & s1 , const QStringRef & s2 ) |
| bool | operator== (QLatin1String s1 , const QStringRef & s2 ) |
| bool | operator== (const QString & s1 , const QStringRef & s2 ) |
| bool | operator== (const QStringRef & s1 , const QStringRef & s2 ) |
| bool | operator> (const QStringRef & s1 , const QStringRef & s2 ) |
| bool | operator>= (const QStringRef & s1 , const QStringRef & s2 ) |
QStringRef provides a read-only subset of the QString API.
A string reference explicitly references a portion of a string () with a given size (), starting at a specific position ()。調用 toString () returns a copy of the data as a real QString 實例。
This class is designed to improve the performance of substring handling when manipulating substrings obtained from existing QString instances. QStringRef avoids the memory allocation and reference counting overhead of a standard QString by simply referencing a part of the original string. This can prove to be advantageous in low level code, such as that used in a parser, at the expense of potentially more complex code.
For most users, there are no semantic benefits to using QStringRef instead of QString since QStringRef requires attention to be paid to memory management issues, potentially making code more complex to write and maintain.
警告: A QStringRef is only valid as long as the referenced string exists. If the original string is deleted, the string reference points to an invalid memory location.
We suggest that you only use this class in stable code where profiling has clearly identified that performance improvements can be made by replacing standard string operations with the optimized substring handling provided by this class.
另請參閱 隱式共享類 .
另請參閱 QStringRef::const_reverse_iterator .
另請參閱 QStringRef::const_iterator .
[constexpr noexcept]
QStringRef::
QStringRef
()
Constructs an empty string reference.
Constructs a string reference to the given string .
Constructs a string reference to the range of characters in the given string specified by the starting position and length in characters.
警告: This function exists to improve performance as much as possible, and performs no bounds checking. For program correctness, position and length must describe a valid substring of string .
This means that the starting position must be positive or 0 and smaller than string 's length, and length must be positive or 0 but smaller than the string's length minus the starting position ; i.e, 0 <= position < string-> length () and 0 <= length <= string-> length () - position must both be satisfied.
[noexcept default]
QStringRef::
QStringRef
(const
QStringRef
&
other
)
構造副本為 other string reference.
[noexcept default]
QStringRef::
~QStringRef
()
Destroys the string reference.
Since this class is only used to refer to string data, and does not take ownership of it, no memory is freed when instances are destroyed.
Appends the string reference to string , and returns a new reference to the combined string data.
返迴字符按給定索引 position in the string reference.
The position 在字符串中必須是有效索引位置 (即 0 <= position < size ()).
返迴字符串中的最後一個字符。如同
at(size() - 1)
.
此函數為兼容 STL (標準模闆庫) 提供。
警告: 在空字符串調用此函數,將構成未定義行為。
另請參閱 front (), at (),和 operator[] ().
返迴常量 STL 樣式迭代器 指嚮字符串中的首個字符。
另請參閱 cbegin (), constBegin (), end (), constEnd (), rbegin (),和 rend ().
如同 begin ().
另請參閱 begin (), constBegin (), cend (), constEnd (), rbegin (),和 rend ().
如同 end ().
另請參閱 end (), constEnd (), cbegin (), constBegin (), rbegin (),和 rend ().
[noexcept]
void
QStringRef::
chop
(
int
n
)
移除 n 個字符從字符串末尾起。
若 n >= size (),結果為空字符串;若 n 為負,相當於傳遞 0。
另請參閱 QString::chop () 和 truncate ().
Returns a substring reference to the size () - len leftmost characters of this string.
注意: 行為未定義若 len 為負或大於 size ().
另請參閱 endsWith (), left (), right (), mid (), chop (),和 truncate ().
Clears the contents of the string reference by making it null and empty.
[static noexcept]
int
QStringRef::
compare
(const
QStringRef
&
s1
, const
QString
&
s2
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive)
比較 s1 with s2 並返迴負整數若 s1 小於 s2 ,正整數若大於 s2 ,和 0 若它們相等。
若 cs is Qt::CaseSensitive , the comparison is case sensitive; otherwise the comparison is case insensitive.
[noexcept]
int
QStringRef::
compare
(
QChar
ch
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
這是重載函數。
比較
*this
with
ch
並返迴負整數若
*this
小於
ch
,正整數若大於
ch
, and zero if they are equal. Here,
ch
interpreted as a string of length one.
若 cs is Qt::CaseSensitive , the comparison is case sensitive; otherwise the comparison is case insensitive.
[noexcept]
int
QStringRef::
compare
(
QLatin1String
other
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
這是重載函數。
比較
*this
with
other
並返迴負整數若
*this
小於
other
,正整數若大於
other
,和 0 若它們相等。
若 cs is Qt::CaseSensitive , the comparison is case sensitive; otherwise the comparison is case insensitive.
相當於
compare(*this, other, cs)
.
這是重載函數。
比較
*this
with
other
並返迴負整數若
*this
小於
other
,正整數若大於
other
, and zero if they are equal. The contents of
other
is interpreted as UTF-8.
若 cs is Qt::CaseSensitive , the comparison is case sensitive; otherwise the comparison is case insensitive.
相當於
compare(*this, other, cs)
.
[noexcept]
int
QStringRef::
compare
(const
QString
&
other
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
這是重載函數。
比較
*this
with
other
並返迴負整數若
*this
小於
other
,正整數若大於
other
,和 0 若它們相等。
若 cs is Qt::CaseSensitive , the comparison is case sensitive; otherwise the comparison is case insensitive.
相當於
compare(*this, other, cs)
.
[noexcept]
int
QStringRef::
compare
(const
QStringRef
&
other
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
這是重載函數。
比較
*this
with
other
並返迴負整數若
*this
小於
other
,正整數若大於
other
,和 0 若它們相等。
若 cs is Qt::CaseSensitive , the comparison is case sensitive; otherwise the comparison is case insensitive.
相當於
compare(*this, other, cs)
.
[static noexcept]
int
QStringRef::
compare
(const
QStringRef
&
s1
,
QLatin1String
s2
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive)
這是重載函數。
比較 s1 with s2 並返迴負整數若 s1 小於 s2 ,正整數若大於 s2 ,和 0 若它們相等。
若 cs is Qt::CaseSensitive , the comparison is case sensitive; otherwise the comparison is case insensitive.
[static noexcept]
int
QStringRef::
compare
(const
QStringRef
&
s1
, const
QStringRef
&
s2
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive)
這是重載函數。
比較 s1 with s2 並返迴負整數若 s1 小於 s2 ,正整數若大於 s2 ,和 0 若它們相等。
若 cs is Qt::CaseSensitive , the comparison is case sensitive; otherwise the comparison is case insensitive.
如同 begin ().
另請參閱 begin (), cend (), constEnd (), rbegin (),和 rend ().
如同 unicode ().
如同 end ().
另請參閱 end (), cend (), cbegin (), constBegin (), rbegin (),和 rend ().
返迴
true
if this string reference contains an occurrence of the string
str
;否則返迴
false
.
若 cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
此函數重載 contains()。
返迴
true
若此字符串包含齣現字符
ch
;否則返迴
false
.
若 cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
此函數重載 contains()。
返迴
true
if this string reference contains an occurrence of the string
str
;否則返迴
false
.
若 cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
[noexcept]
bool
QStringRef::
contains
(
QStringView
str
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
此函數重載 contains()。
返迴
true
if this string reference contains an occurrence of the string view
str
;否則返迴
false
.
若 cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
此函數重載 contains()。
返迴
true
if this string reference contains an occurrence of the string reference
str
;否則返迴
false
.
若 cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
Returns the number of characters referred to by the string reference. Equivalent to size () 和 length ().
返迴 (潛在重疊) 齣現數對於字符串 str in this string reference.
若 cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
另請參閱 QString::count (), contains (),和 indexOf ().
此函數重載 count()。
Returns the number of occurrences of the character ch in the string reference.
若 cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
另請參閱 QString::count (), contains (),和 indexOf ().
此函數重載 count()。
Returns the number of (potentially overlapping) occurrences of the string reference str in this string reference.
若 cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
另請參閱 QString::count (), contains (),和 indexOf ().
如同 rbegin ().
另請參閱 begin (), rbegin (),和 rend ().
如同 rend ().
另請參閱 end (), rend (),和 rbegin ().
如同 unicode ().
返迴常量 STL 樣式迭代器 pointing to the imaginary character after the last character in the list.
另請參閱 cbegin (), constBegin (), end(), constEnd (), rbegin (),和 rend ().
返迴
true
if the string reference ends with
str
;否則返迴
false
.
若 cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
另請參閱 QString::endsWith () 和 startsWith ().
此函數重載 endsWith()。
返迴
true
if the string reference ends with
ch
;否則返迴
false
.
若 cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
另請參閱 QString::endsWith () 和 endsWith ().
此函數重載 endsWith()。
另請參閱 QString::endsWith () 和 endsWith ().
[noexcept]
bool
QStringRef::
endsWith
(
QStringView
str
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
此函數重載 endsWith()。
另請參閱 QString::endsWith () 和 startsWith ().
此函數重載 endsWith()。
另請參閱 QString::endsWith () 和 endsWith ().
Returns the first character in the string. Same as
at(0)
.
此函數為兼容 STL (標準模闆庫) 提供。
警告: 在空字符串調用此函數,將構成未定義行為。
另請參閱 back (), at (),和 operator[] ().
Returns the index position of the first occurrence of the string str in this string reference, searching forward from index position from . Returns -1 if str 找不到。
若 cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
若 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 (), lastIndexOf (), contains (),和 count ().
Returns the index position of the first occurrence of the string str in this string reference, searching forward from index position from . Returns -1 if str 找不到。
若 cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
若 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 (), lastIndexOf (), contains (),和 count ().
此函數重載 indexOf()。
Returns the index position of the first occurrence of the character ch in the string reference, searching forward from index position from . Returns -1 if ch could not be found.
另請參閱 QString::indexOf (), lastIndexOf (), contains (),和 count ().
[noexcept]
int
QStringRef::
indexOf
(
QStringView
str
,
int
from
= 0,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
此函數重載 indexOf()。
Returns the index position of the first occurrence of the string view str in this string reference, searching forward from index position from . Returns -1 if str 找不到。
若 cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
若 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 (), QStringView::indexOf (), lastIndexOf (), contains (),和 count ().
此函數重載 indexOf()。
Returns the index position of the first occurrence of the string reference str in this string reference, searching forward from index position from . Returns -1 if str 找不到。
若 cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
另請參閱 QString::indexOf (), lastIndexOf (), contains (),和 count ().
返迴
true
if the string reference has no characters; otherwise returns
false
.
A string reference is empty if its size is zero.
另請參閱 size ().
返迴
true
if this string reference does not reference a string or if the string it references is null (i.e.
QString::isNull
() is true).
另請參閱 size ().
返迴
true
if the string is read right to left.
另請參閱 QString::isRightToLeft ().
Returns the index position of the last occurrence of the string str in this string reference, searching backward from index position from 。若 from is -1 (default), the search starts at the last character; if from is -2, at the next to last character and so on. Returns -1 if str 找不到。
若 cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
另請參閱 QString::lastIndexOf (), indexOf (), contains (),和 count ().
This function overloads lastIndexOf().
Returns the index position of the last occurrence of the character ch , searching backward from position from .
另請參閱 QString::lastIndexOf (), indexOf (), contains (),和 count ().
This function overloads lastIndexOf().
Returns the index position of the last occurrence of the string str in this string reference, searching backward from index position from 。若 from is -1 (default), the search starts at the last character; if from is -2, at the next to last character and so on. Returns -1 if str 找不到。
若 cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
另請參閱 QString::lastIndexOf (), indexOf (), contains (),和 count ().
[noexcept]
int
QStringRef::
lastIndexOf
(
QStringView
str
,
int
from
= -1,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
This function overloads lastIndexOf().
Returns the index position of the last occurrence of the string view str in this string, searching backward from index position from 。若 from is -1 (default), the search starts at the last character; if from is -2, at the next to last character and so on. Returns -1 if str 找不到。
若 cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
另請參閱 indexOf (), contains (),和 count ().
This function overloads lastIndexOf().
Returns the index position of the last occurrence of the string reference str in this string reference, searching backward from index position from 。若 from is -1 (default), the search starts at the last character; if from is -2, at the next to last character and so on. Returns -1 if str 找不到。
若 cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
另請參閱 QString::lastIndexOf (), indexOf (), contains (),和 count ().
Returns a substring reference to the n leftmost characters of the string.
若 n >= size (), or less than zero, a reference to the entire string is returned.
另請參閱 right (), mid (), startsWith (), chopped (), chop (),和 truncate ().
Returns the number of characters referred to by the string reference. Equivalent to size () 和 count ().
[static]
int
QStringRef::
localeAwareCompare
(const
QStringRef
&
s1
, const
QString
&
s2
)
比較 s1 with s2 並返迴負整數若 s1 小於 s2 ,正整數若大於 s2 ,和 0 若它們相等。
The comparison is performed in a locale- and also platform-dependent manner. Use this function to present sorted lists of strings to the user.
另請參閱 compare (), QLocale ,和 Comparing Strings .
這是重載函數。
比較
*this
with
other
並返迴負整數若
*this
小於
other
,正整數若大於
other
,和 0 若它們相等。
The comparison is performed in a locale- and also platform-dependent manner. Use this function to present sorted lists of strings to the user.
另請參閱 Comparing Strings .
這是重載函數。
比較
*this
with
other
並返迴負整數若
*this
小於
other
,正整數若大於
other
,和 0 若它們相等。
The comparison is performed in a locale- and also platform-dependent manner. Use this function to present sorted lists of strings to the user.
另請參閱 Comparing Strings .
[static]
int
QStringRef::
localeAwareCompare
(const
QStringRef
&
s1
, const
QStringRef
&
s2
)
這是重載函數。
比較 s1 with s2 並返迴負整數若 s1 小於 s2 ,正整數若大於 s2 ,和 0 若它們相等。
The comparison is performed in a locale- and also platform-dependent manner. Use this function to present sorted lists of strings to the user.
另請參閱 Comparing Strings .
Returns a substring reference to n 個字符對於此字符串,起始於指定 position .
若 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 ,或者若 n is -1 (default), the function returns all characters from the specified position onwards.
另請參閱 left (), right (), chopped (), chop (),和 truncate ().
Returns the starting position in the referenced string that is referred to by the string reference.
返迴常量 STL-style reverse iterator pointing to the first character in the string, in reverse order.
另請參閱 begin (), crbegin (),和 rend ().
返迴 STL-style reverse iterator pointing to one past the last character in the string, in reverse order.
另請參閱 end (), crend (),和 rbegin ().
Returns a substring reference to the n rightmost characters of the string.
若 n >= size (), or less than zero, a reference to the entire string is returned.
另請參閱 left (), mid (), endsWith (), chopped (), chop (),和 truncate ().
Returns the number of characters referred to by the string reference. Equivalent to length () 和 count ().
Splits the string into substrings references wherever sep occurs, and returns the list of those strings.
見 QString::split () for how sep , behavior and cs interact to form the result.
注意: All references are valid as long this string is alive. Destroying this string will cause all references to be dangling pointers.
這是重載函數。
返迴
true
if the string reference starts with
str
;否則返迴
false
.
若 cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
另請參閱 QString::startsWith () 和 endsWith ().
This function overloads startsWith().
返迴
true
if the string reference starts with
ch
;否則返迴
false
.
若 cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.
另請參閱 QString::startsWith () 和 endsWith ().
This function overloads startsWith().
另請參閱 QString::startsWith () 和 endsWith ().
[noexcept]
bool
QStringRef::
startsWith
(
QStringView
str
,
Qt::CaseSensitivity
cs
= Qt::CaseSensitive) const
This function overloads startsWith().
另請參閱 QString::startsWith () 和 endsWith ().
This function overloads startsWith().
另請參閱 QString::startsWith () 和 endsWith ().
Returns a pointer to the string referred to by the string reference, or 0 if it does not reference a string.
另請參閱 unicode ().
Returns the string converted to a
double
值。
Returns an infinity if the conversion overflows or 0.0 if the conversion fails for other reasons (e.g. underflow).
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toDouble ()
For historic reasons, this function does not handle thousands group separators. If you need to convert such numbers, use QLocale::toDouble ().
另請參閱 QString::toDouble ().
Returns the string converted to a
float
值。
Returns an infinity if the conversion overflows or 0.0 if the conversion fails for other reasons (e.g. underflow).
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toFloat ()
另請參閱 QString::toFloat ().
Returns the string converted to an
int
使用基
base
, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
若 base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used.
The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toInt ()
另請參閱 QString::toInt ().
Returns a Latin-1 representation of the string as a QByteArray .
The returned byte array is undefined if the string contains non-Latin1 characters. Those characters may be suppressed or replaced with a question mark.
另請參閱 toUtf8 (), toLocal8Bit (),和 QStringEncoder .
Returns the local 8-bit representation of the string as a QByteArray . The returned byte array is undefined if the string contains characters not supported by the local 8-bit encoding.
在 Unix 係統,這相當於 toUtf8 (), on Windows the systems current code page is being used.
If this string contains any characters that cannot be encoded in the locale, the returned byte array is undefined. Those characters may be suppressed or replaced by another.
另請參閱 toLatin1 (), toUtf8 (),和 QStringEncoder .
Returns the string converted to a
long
使用基
base
, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
若 base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used.
The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toLong ()
另請參閱 QString::toLong ().
Returns the string converted to a
long long
使用基
base
, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
若 base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used.
The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toLongLong ()
另請參閱 QString::toLongLong ().
Returns the string converted to a
short
使用基
base
, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
若 base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used.
The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toShort ()
另請參閱 QString::toShort ().
Returns a copy of the string reference as a QString 對象。
If the string reference is not a complete reference of the string (meaning that position () is 0 and size () 等於 string ()-> size ()), this function will allocate a new string to return.
另請參閱 string ().
Returns the string converted to an
unsigned int
使用基
base
, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
若 base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used.
The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toUInt ()
另請參閱 QString::toUInt ().
Returns the string converted to an
unsigned long
使用基
base
, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
若 base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used.
The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toULongLong ()
另請參閱 QString::toULong ().
Returns the string converted to an
unsigned long long
使用基
base
, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
若 base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used.
The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toULongLong ()
另請參閱 QString::toULongLong ().
Returns the string converted to an
unsigned short
使用基
base
, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.
若
ok
不是
nullptr
, failure is reported by setting *
ok
to
false
, and success by setting *
ok
to
true
.
若 base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used.
The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toUShort ()
另請參閱 QString::toUShort ().
Returns a UCS-4/UTF-32 representation of the string as a QList <uint>.
UCS-4 is a Unicode codec and therefore it is lossless. All characters from this string will be encoded in UCS-4. Any invalid sequence of code units in this string is replaced by the Unicode's replacement character (
QChar::ReplacementCharacter
, which corresponds to
U+FFFD
).
The returned list is not \0'-terminated.
另請參閱 toUtf8 (), toLatin1 (), toLocal8Bit (),和 QStringEncoder .
Returns a UTF-8 representation of the string as a QByteArray .
UTF-8 is a Unicode codec and can represent all characters in a Unicode string like QString .
另請參閱 toLatin1 (), toLocal8Bit (),和 QStringEncoder .
返迴從開始到結束之間,已移除空白的字符串。
空白意味著任何字符其。
QChar::isSpace
() 返迴
true
。這包括 ASCII 字符 \t、\n、\v、\f、\r、及 " "。
不像 QString::simplified (),trimmed() 隻留下內部空白。
另請參閱 QString::trimmed ().
[noexcept]
void
QStringRef::
truncate
(
int
position
)
截取字符串按給定 position 索引。
若指定 position 索引超齣字符串末尾,什麼都不發生。
若 position 為負,相當於傳遞 0。
另請參閱 QString::truncate ().
Returns a Unicode representation of the string reference. Since the data stems directly from the referenced string, it is not \0'-terminated unless the string reference includes the string's null terminator.
另請參閱 string ().
This function overloads operator!=().
The s const char pointer is converted to a QStringRef using the fromUtf8() function.
可以禁用此運算符通過定義
QT_NO_CAST_FROM_ASCII
when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through
QObject::tr
(), for example.
返迴
true
if this string is not lexically equal to the parameter string
s
. Otherwise returns
false
.
另請參閱 QT_NO_CAST_FROM_ASCII .
This function overloads operator<().
The s const char pointer is converted to a QStringRef using the fromUtf8() function.
可以禁用此運算符通過定義
QT_NO_CAST_FROM_ASCII
when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through
QObject::tr
(), for example.
返迴
true
if this string is lexically smaller than the parameter string
s
. Otherwise returns
false
.
另請參閱 QT_NO_CAST_FROM_ASCII .
This function overloads operator<=().
The s const char pointer is converted to a QStringRef using the fromUtf8() function.
可以禁用此運算符通過定義
QT_NO_CAST_FROM_ASCII
when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through
QObject::tr
(), for example.
返迴
true
if this string is lexically smaller than or equal to the parameter string
s
. Otherwise returns
false
.
另請參閱 QT_NO_CAST_FROM_ASCII .
Constructs a string reference to the given string and assigns it to this string reference, returning the result.
[noexcept default]
QStringRef
&QStringRef::
operator=
(const
QStringRef
&
other
)
賦值 other string reference to this string reference, and returns the result.
This function overloads operator==().
The s byte array is converted to a QStringRef using the fromUtf8() function. This function stops conversion at the first NUL character found, or the end of the byte array.
可以禁用此運算符通過定義
QT_NO_CAST_FROM_ASCII
when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through
QObject::tr
(), for example.
返迴
true
if this string is lexically equal to the parameter string
s
. Otherwise returns
false
.
另請參閱 QT_NO_CAST_FROM_ASCII .
This function overloads operator>().
The s const char pointer is converted to a QStringRef using the fromUtf8() function.
可以禁用此運算符通過定義
QT_NO_CAST_FROM_ASCII
when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through
QObject::tr
(), for example.
返迴
true
if this string is lexically greater than the parameter string
s
. Otherwise returns
false
.
另請參閱 QT_NO_CAST_FROM_ASCII .
此函數重載運算符 >=()。
The s const char pointer is converted to a QStringRef using the fromUtf8() function.
可以禁用此運算符通過定義
QT_NO_CAST_FROM_ASCII
when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through
QObject::tr
(), for example.
返迴
true
if this string is lexically greater than or equal to the parameter string
s
. Otherwise returns
false
.
另請參閱 QT_NO_CAST_FROM_ASCII .
返迴字符按給定索引 position in the string reference.
The position must be a valid index position in the string reference (i.e., 0 <= position < size ()).
另請參閱 at ().
[noexcept]
bool
operator<
(const
QStringRef
&
s1
, const
QStringRef
&
s2
)
返迴
true
if string reference
s1
is lexically less than string reference
s2
;否則返迴
false
.
另請參閱 Comparing Strings .
[noexcept]
bool
operator<=
(const
QStringRef
&
s1
, const
QStringRef
&
s2
)
返迴
true
if string reference
s1
is lexically less than or equal to string reference
s2
;否則返迴
false
.
另請參閱 Comparing Strings .
[noexcept]
bool
operator==
(
QLatin1String
s1
, const
QStringRef
&
s2
)
返迴
true
若字符串
s1
is lexically equal to string reference
s2
;否則返迴
false
.
[noexcept]
bool
operator==
(const
QString
&
s1
, const
QStringRef
&
s2
)
返迴
true
若字符串
s1
is lexically equal to string reference
s2
;否則返迴
false
.
[noexcept]
bool
operator==
(const
QStringRef
&
s1
, const
QStringRef
&
s2
)
返迴
true
if string reference
s1
is lexically equal to string reference
s2
;否則返迴
false
.
[noexcept]
bool
operator>
(const
QStringRef
&
s1
, const
QStringRef
&
s2
)
返迴
true
if string reference
s1
is lexically greater than string reference
s2
;否則返迴
false
.
另請參閱 Comparing Strings .
[noexcept]
bool
operator>=
(const
QStringRef
&
s1
, const
QStringRef
&
s2
)
返迴
true
if string reference
s1
is lexically greater than or equal to string reference
s2
;否則返迴
false
.
另請參閱 Comparing Strings .