Class StringBase
Represents text as a sequence of characters. Container uses a single dynamic memory allocation to store the characters data. Characters sequence is always null-terminated.
Inheritance
Inherited Members
Assembly: FlaxEngine.dll
File: Engine/Core/Types/String.h
Syntax
public class StringBase<T>
Type Parameters
T
|
Constructors
~StringBase()
Fields
_data
Declaration
protected T* _data = nullptr
Field Value
T
|
_length
Declaration
protected int32 _length = 0
Field Value
int32
|
Methods
Clear()
Clears this instance. Frees the memory and sets the string to empty.
Declaration
public void Clear()
Compare(const StringBase& str, StringSearchCase searchCase=StringSearchCase::CaseSensitive)
Lexicographically tests how this string compares to the other given string. In case sensitive mode 'A' is less than 'a'.
Declaration
public int32 Compare(const StringBase& str, StringSearchCase searchCase=StringSearchCase::CaseSensitive) const
Parameters
StringBase
str
The another string test against. |
StringSearchCase
searchCase
The case sensitivity mode. |
Returns
int32
0 if equal, negative number if less than, positive number if greater than. |
Contains(const StringBase& subStr, StringSearchCase searchCase=StringSearchCase::CaseSensitive)
Checks whether this string contains the specified substring.
Declaration
public bool Contains(const StringBase& subStr, StringSearchCase searchCase=StringSearchCase::CaseSensitive) const
Parameters
StringBase
subStr
The string sequence to search for. |
StringSearchCase
searchCase
The search case sensitivity mode. |
Returns
bool
True if the given substring is contained by ths string, otherwise false. |
Contains(const T* subStr, StringSearchCase searchCase=StringSearchCase::CaseSensitive)
Checks whether this string contains the specified substring.
Declaration
public bool Contains(const T* subStr, StringSearchCase searchCase=StringSearchCase::CaseSensitive) const
Parameters
T
subStr
The string sequence to search for. |
StringSearchCase
searchCase
The search case sensitivity mode. |
Returns
bool
True if the given substring is contained by ths string, otherwise false. |
EndsWith(const StringBase& suffix, StringSearchCase searchCase=StringSearchCase::CaseSensitive)
Declaration
public bool EndsWith(const StringBase& suffix, StringSearchCase searchCase=StringSearchCase::CaseSensitive) const
Parameters
StringBase
suffix
|
StringSearchCase
searchCase
|
Returns
bool
|
EndsWith(T c, StringSearchCase searchCase=StringSearchCase::CaseSensitive)
Declaration
public bool EndsWith(T c, StringSearchCase searchCase=StringSearchCase::CaseSensitive) const
Parameters
T
c
|
StringSearchCase
searchCase
|
Returns
bool
|
Find(const StringBase& subStr, StringSearchCase searchCase=StringSearchCase::CaseSensitive, int32 startPosition=-1)
Searches the string starting from beginning for a substring, and returns index into this string of the first found instance.
Declaration
public int32 Find(const StringBase& subStr, StringSearchCase searchCase=StringSearchCase::CaseSensitive, int32 startPosition=-1) const
Parameters
StringBase
subStr
The string sequence to search for. |
StringSearchCase
searchCase
The search case sensitivity mode. |
int32
startPosition
The start character position to search from. |
Returns
int32
The index of the found substring or -1 if not found. |
Find(const T* subStr, StringSearchCase searchCase=StringSearchCase::CaseSensitive, int32 startPosition=-1)
Searches the string starting from beginning for a substring, and returns index into this string of the first found instance.
Declaration
public int32 Find(const T* subStr, StringSearchCase searchCase=StringSearchCase::CaseSensitive, int32 startPosition=-1) const
Parameters
T
subStr
The string sequence to search for. |
StringSearchCase
searchCase
The search case sensitivity mode. |
int32
startPosition
The start character position to search from. |
Returns
int32
The index of the found substring or -1 if not found. |
Find(T c)
Searches the string for the occurrence of a character.
Declaration
public int32 Find(T c) const
Parameters
T
c
The character to search for. |
Returns
int32
The index of the character position in the string or -1 if not found. |
FindFirstOf(const T* str, int32 startPos = 0)
Searches the string for the first character that matches any of the characters specified in its arguments.
Declaration
public int32 FindFirstOf(const T* str, int32 startPos = 0) const
Parameters
T
str
The pointer to the array of characters that are searched for. |
int32
startPos
The start position of the search. The search only includes characters at or after position, ignoring any possible occurrences before it. |
Returns
int32
The position of the first character that matches. If no matches are found, the function returns -1. |
FindFirstOf(T c, int32 startPos = 0)
Searches the string for the first character that matches the character specified.
Declaration
public int32 FindFirstOf(T c, int32 startPos = 0) const
Parameters
T
c
The character to search for. |
int32
startPos
The start position of the search. The search only includes characters at or after position, ignoring any possible occurrences before it. |
Returns
int32
The position of the first character that matches. If no matches are found, the function returns -1. |
FindLast(const StringBase& subStr, StringSearchCase searchCase=StringSearchCase::CaseSensitive, int32 startPosition=-1)
Searches the string starting from end for a substring, and returns index into this string of the first found instance.
Declaration
public int32 FindLast(const StringBase& subStr, StringSearchCase searchCase=StringSearchCase::CaseSensitive, int32 startPosition=-1) const
Parameters
StringBase
subStr
The string sequence to search for. |
StringSearchCase
searchCase
The search case sensitivity mode. |
int32
startPosition
The start character position to search from. |
Returns
int32
The index of the found substring or -1 if not found. |
FindLast(const T* subStr, StringSearchCase searchCase=StringSearchCase::CaseSensitive, int32 startPosition=-1)
Searches the string starting from end for a substring, and returns index into this string of the first found instance.
Declaration
public int32 FindLast(const T* subStr, StringSearchCase searchCase=StringSearchCase::CaseSensitive, int32 startPosition=-1) const
Parameters
T
subStr
The string sequence to search for. |
StringSearchCase
searchCase
The search case sensitivity mode. |
int32
startPosition
The start character position to search from. |
Returns
int32
The index of the found substring or -1 if not found. |
FindLast(T c)
Searches the string for the last occurrence of a character.
Declaration
public int32 FindLast(T c) const
Parameters
T
c
The character to search for. |
Returns
int32
The index of the character position in the string or -1 if not found. |
Get()
Gets the pointer to the string(or null if text is empty).
Declaration
public T* Get()
Returns
T
The string handle. |
GetText()
Gets the pointer to the string or to the static empty text if string is null. Returned pointer is always valid (read-only).
Declaration
public T* GetText() const
Returns
T
The string handle. |
HasChars()
Returns true if string isn't empty.
Declaration
public bool HasChars() const
Returns
bool
True if string has characters, otherwise false. |
IsEmpty()
Returns true if string is empty.
Declaration
public bool IsEmpty() const
Returns
bool
True if string is empty, otherwise false. |
Length()
Gets the length of the string.
Declaration
public int32 Length() const
Returns
int32
The text length. |
operator*()
Gets the pointer to the string (or null if text is empty).
Declaration
public T* operator*() const
Returns
T
The string handle. |
operator[](int32 index)
Gets the character at the specific index.
Declaration
public T operator[](int32 index)
Parameters
int32
index
The index. |
Returns
T
The character |
Replace(const T* searchText, const T* replacementText, StringSearchCase searchCase=StringSearchCase::CaseSensitive)
Replaces all occurences of searchText within current string with replacementText.
Declaration
public int32 Replace(const T* searchText, const T* replacementText, StringSearchCase searchCase=StringSearchCase::CaseSensitive)
Parameters
T
searchText
String to search for. If empty or null no replacements are done. |
T
replacementText
String to replace with. Null is treated as empty string. |
StringSearchCase
searchCase
|
Returns
int32
Number of replacements made. (In case-sensitive mode if search text and replacement text are equal no replacements are done, and zero is returned.) |
Replace(const T* searchText, int32 searchTextLength, const T* replacementText, int32 replacementTextLength, StringSearchCase searchCase=StringSearchCase::CaseSensitive)
Replaces all occurences of searchText within current string with replacementText.
Declaration
public int32 Replace(const T* searchText, int32 searchTextLength, const T* replacementText, int32 replacementTextLength, StringSearchCase searchCase=StringSearchCase::CaseSensitive)
Parameters
T
searchText
String to search for. |
int32
searchTextLength
Length of searchText. Must be greater than zero. |
T
replacementText
String to replace with. Null is treated as empty string. |
int32
replacementTextLength
Length of replacementText. |
StringSearchCase
searchCase
|
Returns
int32
Number of replacements made (in other words number of occurences of searchText). |
Replace(T searchChar, T replacementChar, StringSearchCase searchCase=StringSearchCase::CaseSensitive)
Declaration
public int32 Replace(T searchChar, T replacementChar, StringSearchCase searchCase=StringSearchCase::CaseSensitive)
Parameters
T
searchChar
|
T
replacementChar
|
StringSearchCase
searchCase
|
Returns
int32
|
ReserveSpace(int32 length)
Reserves space for the characters. Discards the existing contents. Caller is responsible to initialize contents (excluding null-termination character).
Declaration
public void ReserveSpace(int32 length)
Parameters
int32
length
The amount of characters to reserve space for (excluding null-terminated character). |
Resize(int32 length)
Resizes string contents.
Declaration
public void Resize(int32 length)
Parameters
int32
length
New length of the string. |
Reverse()
Reverses the string.
Declaration
public void Reverse()
StartsWith(const StringBase& prefix, StringSearchCase searchCase=StringSearchCase::CaseSensitive)
Declaration
public bool StartsWith(const StringBase& prefix, StringSearchCase searchCase=StringSearchCase::CaseSensitive) const
Parameters
StringBase
prefix
|
StringSearchCase
searchCase
|
Returns
bool
|
StartsWith(T c, StringSearchCase searchCase=StringSearchCase::CaseSensitive)
Declaration
public bool StartsWith(T c, StringSearchCase searchCase=StringSearchCase::CaseSensitive) const
Parameters
T
c
|
StringSearchCase
searchCase
|
Returns
bool
|