TStringView

A fixed-size string builder for TCHAR.

Choose your operating system:

Windows

macOS

Linux

Deprecated

  • 'TFixedAnsiStringBuilder' is deprecated. Please use 'TAnsiStringBuilder' instead!

References

Module

Core

Header

/Engine/Source/Runtime/Core/Public/Containers/StringFwd.h

Include

#include "Containers/StringFwd.h"

Syntax

template<typename CharType>
class TStringView

Remarks

A fixed-size string builder for TCHAR. A fixed-size string builder for ANSICHAR.

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 TEXT("..."_SV).

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(TEXT("ABC"_SV));

Variables

Name Description

Protected variable

const CharType ...

 

DataPtr

Protected variable

int32

 

Size

Constructors

Name Description

Public function

TStringView()

Construct an empty view.

Public function

TStringView

(
    const CharType* InData
)

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

Public function

TStringView

(
    const OtherCharType* InData
)

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

Public function

TStringView

(
    const CharRangeType& InRange
)

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

Public function

TStringView

(
    const CharType* InData,
    int32 InSize
)

Construct a view of InSize characters beginning at InData.

Public function

TStringView

(
    const OtherCharType* InData,
    int32 InSize
)

Construct a view of InSize characters beginning at InData.

Functions

Name Description

Public function Const

constexpr co...

 

begin()

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

Public function Const

int32

 

Compare

(
    const OtherCharType* Other,
    ESearchCase::Type SearchCase
)

Compare this view with a null-terminated string.

Public function Const

int32

 

Compare

(
    TStringView< OtherCharType > Other,
    ESearchCase::Type SearchCase
)

Compare this view with a string view.

Public function Const

int32

 

Compare

(
    OtherRangeType&& Other,
    ESearchCase::Type SearchCase
)

Compare this view with a character range.

Public function Const

bool

 

Contains

(
    ViewType Search
)

Returns whether this view contains the specified substring.

Public function Const

int32

 

CopyString

(
    CharType* Dest,
    int32 CharCount,
    int32 Position
)

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

Public function Const

constexpr co...

 

end()

Public function Const

bool

 

EndsWith

(
    ViewType Suffix,
    ESearchCase::Type SearchCase
)

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

Public function Const

bool

 

EndsWith

(
    CharType Suffix
)

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

Public function Const

bool

 

Equals

(
    const OtherCharType* Other,
    ESearchCase::Type SearchCase
)

Check whether this view is equivalent to a string view.

Public function Const

bool

 

Equals

(
    OtherRangeType&& Other,
    ESearchCase::Type SearchCase
)

Check whether this view is equivalent to a character range.

Public function Const

int32

 

Find

(
    ViewType Search,
    int32 StartPosition
)

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

Public function Const

bool

 

FindChar

(
    CharType Search,
    int32& OutIndex
)

Search the view for the first occurrence of a character.

Public function Const

bool

 

FindLastChar

(
    CharType Search,
    int32& OutIndex
)

Search the view for the last occurrence of a character.

Public function Const

constexpr co...

 

GetData()

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

Public function Const

constexpr bo...

 

IsEmpty()

Returns whether the string view is empty.

Public function Const

ViewType

 

Left

(
    int32 CharCount
)

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

Public function Const

ViewType

 

LeftChop

(
    int32 CharCount
)

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

Public function

void

 

LeftChopInline

(
    int32 CharCount
)

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

Public function

void

 

LeftInline

(
    int32 CharCount
)

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

Public function Const

constexpr in...

 

Len()

Returns the length of the string view.

Public function Const

ViewType

 

Mid

(
    int32 Position,
    int32 CharCount
)

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

Public function

void

 

MidInline

(
    int32 Position,
    int32 CharCount
)

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

Public function

void

 

RemovePrefix

(
    int32 CharCount
)

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

Public function

void

 

RemoveSuffix

(
    int32 CharCount
)

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

Public function

void

 

Reset()

Resets to an empty view

Public function Const

ViewType

 

Right

(
    int32 CharCount
)

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

Public function Const

ViewType

 

RightChop

(
    int32 CharCount
)

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

Public function

void

 

RightChopInline

(
    int32 CharCount
)

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

Public function

void

 

RightInline

(
    int32 CharCount
)

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

Public function Const

bool

 

StartsWith

(
    CharType Prefix
)

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

Public function Const

bool

 

StartsWith

(
    ViewType Prefix,
    ESearchCase::Type SearchCase
)

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

Public function Const

ViewType

 

SubStr

(
    int32 Position,
    int32 CharCount
)

Alias for Mid.

Public function Const

ViewType

 

TrimEnd()

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

Public function

void

 

TrimEndInline()

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

Public function Const

ViewType

 

TrimStart()

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

Public function Const

ViewType

 

TrimStartAndEnd()

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

Public function

void

 

TrimStartAndEndInline()

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

Public function

void

 

TrimStartInline()

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

Operators

Name Description

Public function Const

const CharTy...

 

operator[]

(
    int32 Index
)

Access the character at the given index in the view.

Typedefs

Name

Description

ElementType

ViewType