UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TStringView< CharType > Class Template Reference

#include <StringView.h>

Public Types

using ElementType = CharType
 
using ViewType = TStringView< CharType >
 

Public Member Functions

constexpr TStringView ()=default
 
constexpr TStringView (const CharType *InData UE_LIFETIMEBOUND)
 
constexpr TStringView (const CharType *InData UE_LIFETIMEBOUND, int32 InSize)
 
template<UE::CCompatibleCharType< CharType > OtherCharType>
 TStringView (const OtherCharType *InData UE_LIFETIMEBOUND)
 
template<UE::CCompatibleCharType< CharType > OtherCharType>
constexpr TStringView (const OtherCharType *InData UE_LIFETIMEBOUND, int32 InSize)
 
template<UE::CNotCVRefTo< ViewType > CharRangeType>
requires (!std::is_pointer_v<std::decay_t<CharRangeType>> && UE::CCompatibleStringViewable<CharRangeType, CharType>)
constexpr TStringView (const CharRangeType &InRange UE_LIFETIMEBOUND)
 
const CharType & operator[] (int32 Index) const
 
constexpr const CharType * GetData () const
 
constexpr SIZE_T NumBytes () const
 
constexpr int32 Len () const
 
constexpr bool IsEmpty () const
 
void RemovePrefix (int32 CharCount)
 
void RemoveSuffix (int32 CharCount)
 
void Reset ()
 
int32 CopyString (CharType *Dest, int32 CharCount, int32 Position=0) const
 
ViewType SubStr (int32 Position, int32 CharCount) const
 
ViewType Left (int32 CharCount) const
 
ViewType LeftChop (int32 CharCount) const
 
ViewType Right (int32 CharCount) const
 
ViewType RightChop (int32 CharCount) const
 
ViewType Mid (int32 Position, int32 CharCount=MAX_int32) const
 
ViewType TrimStartAndEnd () const
 
ViewType TrimStart () const
 
ViewType TrimEnd () const
 
void LeftInline (int32 CharCount)
 
void LeftChopInline (int32 CharCount)
 
void RightInline (int32 CharCount)
 
void RightChopInline (int32 CharCount)
 
void MidInline (int32 Position, int32 CharCount=MAX_int32)
 
void TrimStartAndEndInline ()
 
void TrimStartInline ()
 
void TrimEndInline ()
 
template<UE::CCharType OtherCharType>
bool Equals (TStringView< OtherCharType > OtherView, ESearchCase::Type SearchCase=ESearchCase::CaseSensitive) const
 
template<UE::CStringViewable OtherRangeType>
bool Equals (const OtherRangeType &Other, ESearchCase::Type SearchCase=ESearchCase::CaseSensitive) const
 
template<UE::CCharType OtherCharType>
bool Equals (const OtherCharType *Other, ESearchCase::Type SearchCase=ESearchCase::CaseSensitive) const
 
template<UE::CStringViewable OtherRangeType>
int32 Compare (const OtherRangeType &Other, ESearchCase::Type SearchCase=ESearchCase::CaseSensitive) const
 
template<UE::CCharType OtherCharType>
int32 Compare (TStringView< OtherCharType > Other, ESearchCase::Type SearchCase=ESearchCase::CaseSensitive) const
 
template<UE::CCharType OtherCharType>
int32 Compare (const OtherCharType *Other, ESearchCase::Type SearchCase=ESearchCase::CaseSensitive) const
 
bool StartsWith (CharType Prefix) const
 
bool StartsWith (ViewType Prefix, ESearchCase::Type SearchCase=ESearchCase::IgnoreCase) const
 
bool EndsWith (CharType Suffix) const
 
bool EndsWith (ViewType Suffix, ESearchCase::Type SearchCase=ESearchCase::IgnoreCase) const
 
int32 Find (ViewType Search, int32 StartPosition=0, ESearchCase::Type SearchCase=ESearchCase::CaseSensitive) const
 
bool Contains (ViewType Search, ESearchCase::Type SearchCase=ESearchCase::CaseSensitive) const
 
bool FindChar (CharType Search, int32 &OutIndex) const
 
bool FindLastChar (CharType Search, int32 &OutIndex) const
 
UE_FORCEINLINE_HINT bool IsValidIndex (int32 Index) const
 
bool UEOpEquals (TStringView Rhs) const
 
bool UEOpLessThan (TStringView Rhs) const
 
template<UE::CConvertibleTo< TStringView > CharRangeType>
UE_REWRITE auto UEOpEquals (CharRangeType &&Rhs) const
 
template<UE::CConvertibleTo< TStringView > CharRangeType>
UE_REWRITE auto UEOpLessThan (CharRangeType &&Rhs)
 
template<UE::CConvertibleTo< TStringView > CharRangeType>
UE_REWRITE auto UEOpGreaterThan (CharRangeType &&Rhs)
 
UE_REWRITE bool UEOpEquals (const CharType *Rhs) const
 
constexpr const CharType * begin () const
 
constexpr const CharType * end () const
 
constexpr TReversePointerIterator< const CharType > rbegin () const
 
constexpr TReversePointerIterator< const CharType > rend () const
 

Protected Attributes

const CharType * DataPtr = nullptr
 
int32 Size = 0
 

Friends

constexpr auto GetNum (TStringView String)
 
uint32 GetTypeHash (TStringView View)
 

Detailed Description

template<UE::CCharType CharType>
class TStringView< CharType >

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.

FString String(TEXT("ABC"));
const TCHAR* CString = *String;
TStringBuilder<16> StringBuilder;
StringBuilder.Append(TEXT("ABC"));
UseString(StringBuilder);
UseString(TEXT("ABC"));
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define TEXTVIEW(str)
Definition StringView.h:553
BuilderType & Append(const OtherCharType *const String, const int32 Length)
Definition StringBuilder.h:238
Definition StringBuilder.h:509

Member Typedef Documentation

◆ ElementType

template<UE::CCharType CharType>
using TStringView< CharType >::ElementType = CharType

◆ ViewType

template<UE::CCharType CharType>
using TStringView< CharType >::ViewType = TStringView<CharType>

Constructor & Destructor Documentation

◆ TStringView() [1/6]

template<UE::CCharType CharType>
constexpr TStringView< CharType >::TStringView ( )
constexprdefault

Construct an empty view.

◆ TStringView() [2/6]

template<UE::CCharType CharType>
constexpr TStringView< CharType >::TStringView ( const CharType *InData  UE_LIFETIMEBOUND)
inlineconstexpr

Construct a view of the null-terminated string pointed to by InData.

◆ TStringView() [3/6]

template<UE::CCharType CharType>
constexpr TStringView< CharType >::TStringView ( const CharType *InData  UE_LIFETIMEBOUND,
int32  InSize 
)
inlineconstexpr

Construct a view of InSize characters beginning at InData.

◆ TStringView() [4/6]

template<UE::CCharType CharType>
template<UE::CCompatibleCharType< CharType > OtherCharType>
TStringView< CharType >::TStringView ( const OtherCharType *InData  UE_LIFETIMEBOUND)
inline

Construct a view of the null-terminated string pointed to by InData.

◆ TStringView() [5/6]

template<UE::CCharType CharType>
template<UE::CCompatibleCharType< CharType > OtherCharType>
constexpr TStringView< CharType >::TStringView ( const OtherCharType *InData  UE_LIFETIMEBOUND,
int32  InSize 
)
inlineconstexpr

Construct a view of InSize characters beginning at InData.

◆ TStringView() [6/6]

template<UE::CCharType CharType>
template<UE::CNotCVRefTo< ViewType > CharRangeType>
requires (!std::is_pointer_v<std::decay_t<CharRangeType>> && UE::CCompatibleStringViewable<CharRangeType, CharType>)
constexpr TStringView< CharType >::TStringView ( const CharRangeType &InRange  UE_LIFETIMEBOUND)
inlineconstexpr

Construct a view from a contiguous range of characters, such as FString or TStringBuilder.

Member Function Documentation

◆ begin()

template<UE::CCharType CharType>
constexpr const CharType * TStringView< CharType >::begin ( ) const
inlineconstexpr

DO NOT USE DIRECTLY STL-like iterators to enable range-based for loop support.

◆ Compare() [1/3]

template<UE::CCharType CharType>
template<UE::CCharType OtherCharType>
int32 TStringView< CharType >::Compare ( const OtherCharType Other,
ESearchCase::Type  SearchCase = ESearchCase::CaseSensitive 
) const
inline

Compare this view with a null-terminated string.

Parameters
OtherA null-terminated string that is comparable with the character type of this view.
SearchCaseWhether the comparison should ignore case.
Returns
0 is equal, negative if this view is less, positive if this view is greater.

◆ Compare() [2/3]

template<UE::CCharType CharType>
template<UE::CStringViewable OtherRangeType>
int32 TStringView< CharType >::Compare ( const OtherRangeType Other,
ESearchCase::Type  SearchCase = ESearchCase::CaseSensitive 
) const
inline

Compare this view with a character range.

Parameters
OtherA character range that is comparable with the character type of this view.
SearchCaseWhether the comparison should ignore case.
Returns
0 is equal, negative if this view is less, positive if this view is greater.

◆ Compare() [3/3]

template<UE::CCharType CharType>
template<UE::CCharType OtherCharType>
int32 TStringView< CharType >::Compare ( TStringView< OtherCharType Other,
ESearchCase::Type  SearchCase = ESearchCase::CaseSensitive 
) const
inline

Compare this view with a string view.

Parameters
OtherA string view that is comparable with the character type of this view.
SearchCaseWhether the comparison should ignore case.
Returns
0 is equal, negative if this view is less, positive if this view is greater.

◆ Contains()

template<UE::CCharType CharType>
bool TStringView< CharType >::Contains ( ViewType  Search,
ESearchCase::Type  SearchCase = ESearchCase::CaseSensitive 
) const
inline

Returns whether this view contains the specified substring.

Parameters
SearchText to search for
SearchCaseIndicates whether the search is case sensitive or not
Returns
True if the view contains the search string, otherwise false.

◆ CopyString()

template<UE::CCharType CharType>
int32 TStringView< CharType >::CopyString ( CharType *  Dest,
int32  CharCount,
int32  Position = 0 
) const
inline

Copy characters from the view into a destination buffer without null termination.

Parameters
DestBuffer to write into. Must have space for at least CharCount characters.
CharCountThe maximum number of characters to copy.
PositionThe offset into the view from which to start copying.
Returns
The number of characters written to the destination buffer.

◆ end()

template<UE::CCharType CharType>
constexpr const CharType * TStringView< CharType >::end ( ) const
inlineconstexpr

◆ EndsWith() [1/2]

template<UE::CCharType CharType>
bool TStringView< CharType >::EndsWith ( CharType  Suffix) const
inline

Returns whether this view ends with the suffix character compared case-sensitively.

◆ EndsWith() [2/2]

template<UE::CCharType CharType>
bool TStringView< CharType >::EndsWith ( ViewType  Suffix,
ESearchCase::Type  SearchCase = ESearchCase::IgnoreCase 
) const
inline

Returns whether this view ends with the suffix with optional case sensitivity.

◆ Equals() [1/3]

template<UE::CCharType CharType>
template<UE::CCharType OtherCharType>
bool TStringView< CharType >::Equals ( const OtherCharType Other,
ESearchCase::Type  SearchCase = ESearchCase::CaseSensitive 
) const
inline

Check whether this view is equivalent to a string view.

Parameters
OtherA string that is comparable with the character type of this view.
SearchCaseWhether the comparison should ignore case.

◆ Equals() [2/3]

template<UE::CCharType CharType>
template<UE::CStringViewable OtherRangeType>
bool TStringView< CharType >::Equals ( const OtherRangeType Other,
ESearchCase::Type  SearchCase = ESearchCase::CaseSensitive 
) const
inline

Check whether this view is equivalent to a character range.

Parameters
OtherA character range that is comparable with the character type of this view.
SearchCaseWhether the comparison should ignore case.

◆ Equals() [3/3]

template<UE::CCharType CharType>
template<UE::CCharType OtherCharType>
bool TStringView< CharType >::Equals ( TStringView< OtherCharType OtherView,
ESearchCase::Type  SearchCase = ESearchCase::CaseSensitive 
) const
inline

Check whether this view is equivalent to another view.

Parameters
OtherViewA string view that is comparable with the character type of this view.
SearchCaseWhether the comparison should ignore case.
Returns
0 is equal, negative if this view is less, positive if this view is greater.

◆ Find()

template<UE::CCharType CharType>
int32 TStringView< CharType >::Find ( ViewType  Search,
int32  StartPosition = 0,
ESearchCase::Type  SearchCase = ESearchCase::CaseSensitive 
) const
inline

Search the view for the first occurrence of a search string.

Parameters
SearchThe string to search for. Comparison is lexicographic.
StartPositionThe character position to start searching from.
SearchCaseIndicates whether the search is case sensitive or not
Returns
The index of the first occurrence of the search string if found, otherwise INDEX_NONE.

◆ FindChar()

template<UE::CCharType CharType>
bool TStringView< CharType >::FindChar ( CharType  Search,
int32 OutIndex 
) const
inline

Search the view for the first occurrence of a character.

Parameters
SearchThe character to search for. Comparison is lexicographic.
OutIndex[out] The position at which the character was found, or INDEX_NONE if not found.
Returns
True if the character was found in the view, otherwise false.

◆ FindLastChar()

template<UE::CCharType CharType>
bool TStringView< CharType >::FindLastChar ( CharType  Search,
int32 OutIndex 
) const
inline

Search the view for the last occurrence of a character.

Parameters
SearchThe character to search for. Comparison is lexicographic.
OutIndex[out] The position at which the character was found, or INDEX_NONE if not found.
Returns
True if the character was found in the view, otherwise false.

◆ GetData()

template<UE::CCharType CharType>
constexpr const CharType * TStringView< CharType >::GetData ( ) const
inlineconstexpr

Returns a pointer to the start of the view. This is NOT guaranteed to be null-terminated!

◆ IsEmpty()

template<UE::CCharType CharType>
constexpr bool TStringView< CharType >::IsEmpty ( ) const
inlineconstexpr

Returns whether the string view is empty.

◆ IsValidIndex()

template<UE::CCharType CharType>
UE_FORCEINLINE_HINT bool TStringView< CharType >::IsValidIndex ( int32  Index) const
inline

Tests if index is valid, i.e. greater than or equal to zero, and less than the number of characters in the string view.

Parameters
IndexIndex to test.
Returns
True if index is valid. False otherwise.

◆ Left()

template<UE::CCharType CharType>
TStringView< CharType > TStringView< CharType >::Left ( int32  CharCount) const
inline

Returns the left-most part of the view by taking the given number of characters from the left.

◆ LeftChop()

template<UE::CCharType CharType>
TStringView< CharType > TStringView< CharType >::LeftChop ( int32  CharCount) const
inline

Returns the left-most part of the view by chopping the given number of characters from the right.

◆ LeftChopInline()

template<UE::CCharType CharType>
void TStringView< CharType >::LeftChopInline ( int32  CharCount)
inline

Modifies the view by chopping the given number of characters from the right.

◆ LeftInline()

template<UE::CCharType CharType>
void TStringView< CharType >::LeftInline ( int32  CharCount)
inline

Modifies the view to be the given number of characters from the left.

◆ Len()

template<UE::CCharType CharType>
constexpr int32 TStringView< CharType >::Len ( ) const
inlineconstexpr

Returns the length of the string view.

◆ Mid()

template<UE::CCharType CharType>
TStringView< CharType > TStringView< CharType >::Mid ( int32  Position,
int32  CharCount = MAX_int32 
) const
inline

Returns the middle part of the view by taking up to the given number of characters from the given position.

◆ MidInline()

template<UE::CCharType CharType>
void TStringView< CharType >::MidInline ( int32  Position,
int32  CharCount = MAX_int32 
)
inline

Modifies the view to be the middle part by taking up to the given number of characters from the given position.

◆ NumBytes()

template<UE::CCharType CharType>
constexpr SIZE_T TStringView< CharType >::NumBytes ( ) const
inlineconstexpr
Returns
Number of bytes used for the characters in the string view

◆ operator[]()

template<UE::CCharType CharType>
const CharType & TStringView< CharType >::operator[] ( int32  Index) const
inline

Access the character at the given index in the view.

◆ rbegin()

template<UE::CCharType CharType>
constexpr TReversePointerIterator< const CharType > TStringView< CharType >::rbegin ( ) const
inlineconstexpr

◆ RemovePrefix()

template<UE::CCharType CharType>
void TStringView< CharType >::RemovePrefix ( int32  CharCount)
inline

Modifies the view to remove the given number of characters from the start.

◆ RemoveSuffix()

template<UE::CCharType CharType>
void TStringView< CharType >::RemoveSuffix ( int32  CharCount)
inline

Modifies the view to remove the given number of characters from the end.

◆ rend()

template<UE::CCharType CharType>
constexpr TReversePointerIterator< const CharType > TStringView< CharType >::rend ( ) const
inlineconstexpr

◆ Reset()

template<UE::CCharType CharType>
void TStringView< CharType >::Reset ( )
inline

Resets to an empty view

◆ Right()

template<UE::CCharType CharType>
TStringView< CharType > TStringView< CharType >::Right ( int32  CharCount) const
inline

Returns the right-most part of the view by taking the given number of characters from the right.

◆ RightChop()

template<UE::CCharType CharType>
TStringView< CharType > TStringView< CharType >::RightChop ( int32  CharCount) const
inline

Returns the right-most part of the view by chopping the given number of characters from the left.

◆ RightChopInline()

template<UE::CCharType CharType>
void TStringView< CharType >::RightChopInline ( int32  CharCount)
inline

Modifies the view by chopping the given number of characters from the left.

◆ RightInline()

template<UE::CCharType CharType>
void TStringView< CharType >::RightInline ( int32  CharCount)
inline

Modifies the view to be the given number of characters from the right.

◆ StartsWith() [1/2]

template<UE::CCharType CharType>
bool TStringView< CharType >::StartsWith ( CharType  Prefix) const
inline

Returns whether this view starts with the prefix character compared case-sensitively.

◆ StartsWith() [2/2]

template<UE::CCharType CharType>
bool TStringView< CharType >::StartsWith ( ViewType  Prefix,
ESearchCase::Type  SearchCase = ESearchCase::IgnoreCase 
) const
inline

Returns whether this view starts with the prefix with optional case sensitivity.

◆ SubStr()

template<UE::CCharType CharType>
ViewType TStringView< CharType >::SubStr ( int32  Position,
int32  CharCount 
) const
inline

Alias for Mid.

◆ TrimEnd()

template<UE::CCharType CharType>
TStringView< CharType > TStringView< CharType >::TrimEnd ( ) const
inline

Returns the left part of the view before any whitespace at the end.

◆ TrimEndInline()

template<UE::CCharType CharType>
void TStringView< CharType >::TrimEndInline ( )
inline

Modifies the view to be the left part before any whitespace at the end.

◆ TrimStart()

template<UE::CCharType CharType>
TStringView< CharType > TStringView< CharType >::TrimStart ( ) const
inline

Returns the right part of the view after any whitespace at the start.

◆ TrimStartAndEnd()

template<UE::CCharType CharType>
TStringView< CharType > TStringView< CharType >::TrimStartAndEnd ( ) const
inline

Returns the middle part of the view between any whitespace at the start and end.

◆ TrimStartAndEndInline()

template<UE::CCharType CharType>
void TStringView< CharType >::TrimStartAndEndInline ( )
inline

Modifies the view to be the middle part between any whitespace at the start and end.

◆ TrimStartInline()

template<UE::CCharType CharType>
void TStringView< CharType >::TrimStartInline ( )
inline

Modifies the view to be the right part after any whitespace at the start.

◆ UEOpEquals() [1/3]

template<UE::CCharType CharType>
template<UE::CConvertibleTo< TStringView > CharRangeType>
UE_REWRITE auto TStringView< CharType >::UEOpEquals ( CharRangeType &&  Rhs) const
inline

◆ UEOpEquals() [2/3]

template<UE::CCharType CharType>
UE_REWRITE bool TStringView< CharType >::UEOpEquals ( const CharType *  Rhs) const
inline

◆ UEOpEquals() [3/3]

template<UE::CCharType CharType>
bool TStringView< CharType >::UEOpEquals ( TStringView< CharType >  Rhs) const
inline

◆ UEOpGreaterThan()

template<UE::CCharType CharType>
template<UE::CConvertibleTo< TStringView > CharRangeType>
UE_REWRITE auto TStringView< CharType >::UEOpGreaterThan ( CharRangeType &&  Rhs)
inline

◆ UEOpLessThan() [1/2]

template<UE::CCharType CharType>
template<UE::CConvertibleTo< TStringView > CharRangeType>
UE_REWRITE auto TStringView< CharType >::UEOpLessThan ( CharRangeType &&  Rhs)
inline

◆ UEOpLessThan() [2/2]

template<UE::CCharType CharType>
bool TStringView< CharType >::UEOpLessThan ( TStringView< CharType >  Rhs) const
inline

Friends And Related Symbol Documentation

◆ GetNum

template<UE::CCharType CharType>
constexpr auto GetNum ( TStringView< CharType >  String)
friend

◆ GetTypeHash

template<UE::CCharType CharType>
uint32 GetTypeHash ( TStringView< CharType >  View)
friend

Case insensitive string hash function.

Member Data Documentation

◆ DataPtr

template<UE::CCharType CharType>
const CharType* TStringView< CharType >::DataPtr = nullptr
protected

◆ Size

template<UE::CCharType CharType>
int32 TStringView< CharType >::Size = 0
protected

The documentation for this class was generated from the following files: