Navigation
Unreal Engine C++ API Reference > Runtime > Core > Containers
References
Module | Core |
Header | /Engine/Source/Runtime/Core/Public/Containers/StringView.h |
Include | #include "Containers/StringView.h" |
Syntax
template<typename CharType>
class TStringView
Remarks
A string view is a non-owning view of a range of characters.
Ensure that the underlying string is valid for the lifetime of the string view.
Be careful when constructing a string view from a temporary. Make a local copy if necessary.
FStringView View = Object->GetPathName(); // Invalid
FString PathName = Object->GetPathName(); // Valid FStringView View = PathName;
void ProcessPath(FStringView Path); // Valid ProcessPath(Object->GetPathName());
A string view is implicitly constructible from null-terminated strings, from contiguous ranges of characters such as FString and TStringBuilder, and from literals such as TEXTVIEW("...").
A string view is cheap to copy and is meant to be passed by value. Avoid passing by reference.
A string view is not guaranteed to represent a null-terminated string.
Log or format a string view using UE_LOG(TEXT("%.*s"), View.Len(), View.GetData());
A string view is a good fit for function parameters where the function has no requirements for how the string is stored. A caller may use FString, FStringView, TStringBuilder, a char array, a null-terminated string, or any other type which can convert to a string view.
The UE::String namespace contains many functions that can operate on string views. Most of these functions can be found in String/___.h in Core.
voidUseString(FStringViewInString);FStringString(TEXT("ABC"));constTCHAR*CString=*String;TStringBuilder<16>StringBuilder;StringBuilder.Append(TEXT("ABC"));UseString(String);UseString(CString);UseString(StringBuilder);UseString(TEXT("ABC"));UseString(TEXTVIEW("ABC"));
Variables
Type | Name | Description | |
---|---|---|---|
![]() |
const CharType * | DataPtr | |
![]() |
int32 | Size |
Constructors
Type | Name | Description | |
---|---|---|---|
![]() |
constexpr | TStringView () |
Construct an empty view. |
![]() |
constexpr | TStringView
(
const CharType* InData |
Construct a view of the null-terminated string pointed to by InData. |
![]() |
constexpr | TStringView
(
const OtherCharType* InData |
Construct a view of the null-terminated string pointed to by InData. |
![]() |
constexpr | TStringView
(
const CharRangeType& InRange |
Construct a view from a contiguous range of characters, such as FString or TStringBuilder. |
![]() |
constexpr | TStringView
(
const CharType* InData, |
Construct a view of InSize characters beginning at InData. |
![]() |
constexpr | TStringView
(
const OtherCharType* InData, |
Construct a view of InSize characters beginning at InData. |
Functions
Type | Name | Description | |
---|---|---|---|
![]() ![]() |
const CharType * | begin () |
DO NOT USE DIRECTLY STL-like iterators to enable range-based for loop support. |
![]() ![]() |
int32 | Compare
(
const OtherCharType* Other, |
Compare this view with a null-terminated string. |
![]() ![]() |
int32 | Compare
(
TStringView< OtherCharType > Other, |
Compare this view with a string view. |
![]() ![]() |
int32 | Compare
(
OtherRangeType&& Other, |
Compare this view with a character range. |
![]() ![]() |
bool | Contains
(
ViewType Search, |
Returns whether this view contains the specified substring. |
![]() ![]() |
int32 | CopyString
(
CharType* Dest, |
Copy characters from the view into a destination buffer without null termination. |
![]() ![]() |
const CharType * | end () |
|
![]() ![]() |
bool | EndsWith
(
ViewType Suffix, |
Returns whether this view ends with the suffix with optional case sensitivity. |
![]() ![]() |
bool | EndsWith
(
CharType Suffix |
Returns whether this view ends with the suffix character compared case-sensitively. |
![]() ![]() |
bool | Equals
(
const OtherCharType* Other, |
Check whether this view is equivalent to a string view. |
![]() ![]() |
bool | Equals
(
OtherRangeType&& Other, |
Check whether this view is equivalent to a character range. |
![]() ![]() |
int32 | Find
(
ViewType Search, |
Search the view for the first occurrence of a search string. |
![]() ![]() |
bool | Search the view for the first occurrence of a character. | |
![]() ![]() |
bool | FindLastChar
(
CharType Search, |
Search the view for the last occurrence of a character. |
![]() ![]() |
const CharType * | GetData () |
Returns a pointer to the start of the view. This is NOT guaranteed to be null-terminated! |
![]() ![]() |
bool | IsEmpty () |
Returns whether the string view is empty. |
![]() ![]() |
bool | IsValidIndex
(
int32 Index |
Tests if index is valid, i.e. greater than or equal to zero, and less than the number of characters in the string view. |
![]() ![]() |
ViewType | Returns the left-most part of the view by taking the given number of characters from the left. | |
![]() ![]() |
ViewType | Returns the left-most part of the view by chopping the given number of characters from the right. | |
![]() |
void | LeftChopInline
(
int32 CharCount |
Modifies the view by chopping the given number of characters from the right. |
![]() |
void | LeftInline
(
int32 CharCount |
Modifies the view to be the given number of characters from the left. |
![]() ![]() |
int32 | Len () |
Returns the length of the string view. |
![]() ![]() |
ViewType | Returns the middle part of the view by taking up to the given number of characters from the given position. | |
![]() |
void | Modifies the view to be the middle part by taking up to the given number of characters from the given position. | |
![]() ![]() |
TReversePointerIterator< const CharType > | rbegin () |
|
![]() |
void | RemovePrefix
(
int32 CharCount |
Modifies the view to remove the given number of characters from the start. |
![]() |
void | RemoveSuffix
(
int32 CharCount |
Modifies the view to remove the given number of characters from the end. |
![]() ![]() |
TReversePointerIterator< const CharType > | rend () |
|
![]() |
void | Reset () |
Resets to an empty view |
![]() ![]() |
ViewType | Returns the right-most part of the view by taking the given number of characters from the right. | |
![]() ![]() |
ViewType | Returns the right-most part of the view by chopping the given number of characters from the left. | |
![]() |
void | RightChopInline
(
int32 CharCount |
Modifies the view by chopping the given number of characters from the left. |
![]() |
void | RightInline
(
int32 CharCount |
Modifies the view to be the given number of characters from the right. |
![]() ![]() |
bool | StartsWith
(
CharType Prefix |
Returns whether this view starts with the prefix character compared case-sensitively. |
![]() ![]() |
bool | StartsWith
(
ViewType Prefix, |
Returns whether this view starts with the prefix with optional case sensitivity. |
![]() ![]() |
ViewType | Alias for Mid. | |
![]() ![]() |
ViewType | TrimEnd () |
Returns the left part of the view before any whitespace at the end. |
![]() |
void | Modifies the view to be the left part before any whitespace at the end. | |
![]() ![]() |
ViewType | TrimStart () |
Returns the right part of the view after any whitespace at the start. |
![]() ![]() |
ViewType | Returns the middle part of the view between any whitespace at the start and end. | |
![]() |
void | Modifies the view to be the middle part between any whitespace at the start and end. | |
![]() |
void | Modifies the view to be the right part after any whitespace at the start. |
Operators
Type | Name | Description | |
---|---|---|---|
![]() ![]() |
const CharType & | operator[]
(
int32 Index |
Access the character at the given index in the view. |
Typedefs
Name | Description |
---|---|
ElementType | |
ViewType |