RealDocs

FString::Contains

function Core Since 4.0
#include "Containers/UnrealString.h"
Access: public Specifiers: inlineconst

Description

Returns true if this string contains the specified substring. An empty substring always returns true.

Signature

bool Contains(const TCHAR* SubStr, ESearchCase::Type SearchCase = ESearchCase::IgnoreCase, ESearchDir::Type SearchDir = ESearchDir::FromStart) const

Parameters

Name Type Description Default
SubStr const TCHAR* The substring to search for.
SearchCase ESearchCase::Type Whether the search is case-sensitive or case-insensitive. ESearchCase::IgnoreCase
SearchDir ESearchDir::Type Whether to search from the start or the end of the string. ESearchDir::FromStart

Return Type

bool

Caveats & Gotchas

  • The default search is case-insensitive. Pass ESearchCase::CaseSensitive explicitly when comparing asset paths or identifiers — forgetting this is a common source of bugs.
  • SearchDir affects where the search begins but does not restrict what counts as a match; Contains returns true if the substring exists anywhere in the string regardless.
  • An empty substring always returns true, which can surprise you when SubStr originates from user input.

Example

Case-insensitive and case-sensitive check C++
FString Path = TEXT("/Game/Characters/Hero");

// Case-insensitive (default)
if (Path.Contains(TEXT("characters")))
{
	// matches
}

// Case-sensitive
if (Path.Contains(TEXT("Characters"), ESearchCase::CaseSensitive))
{
	// also matches
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.