String
UFG::qString
String is UTF-8 based string class. By default, String allocates memory from main memory pool.
Methods
Method | Description |
---|---|
find | Returns index of the first character of the given text. |
Format | Format arguments according to the format string. |
ReplaceExtension | Returns a new string with replaced extension. |
ReplaceCharInPlace | Replace all characters with the given character. |
ReplaceString | Replace a text with the given text. |
Substring | Returns a substring ([start, start + length]). |
StartsWith | Checks if the string begins with the given text. |
EndsWith | Checks if the string ends with the given text. |
Trim | Returns a new string with whitespace trimmed. |
MakeLower | Converts the character string to lowercase. |
MakeUpper | Converts the character string to uppercase. |
ToLower | Returns a new string converted to lowercase. |
ToUpper | Returns a new string converted to uppercase. |
GetFilePath | Returns a new string with file path. |
GetFilePathWithoutExtension | Returns a new string with file path without extension. |
GetFilename | Returns a new string with file name. |
GetFilenameWithoutExtension | Returns a new string with file name without extension. |
find
int find(const char* str);
Example:
qString str = "filename.perm.bin";str.find(".perm.bin"); // 8 (found)str.find(".temp.bin"); // -1 (fail to find)
Format
template <typename... Args>void Format(const char* format, Args... args);
Example:
qString str;str.Format("%s: %d", "Value", 123); // str -> "Value: 123"
ReplaceExtension
qString ReplaceExtension(const char* ext);
Example:
qString str = "filename.txt";str.ReplaceExtension(".bin"); // "filename.bin"
ReplaceCharInPlace
int ReplaceCharInPlace(char search_char, char replace_char);
Example:
qString str = "111bbbccc";str.ReplaceCharInPlace('1', 'a'); // 3 (str -> "aaabbbccc")
ReplaceString
bool ReplaceString(const char* find_text, const char* replace_text, bool ignore_case = false);
Example:
qString str = "abcdef";str.ReplaceString("abc", "123"); // true (str -> "123def")
Substring
qString Substring(int start, int length);
Example:
qString str = "filename.perm.bin";str.Substring(4, 4); // "name"
StartsWith
bool StartsWith(const char* text, int length = -1);
Example:
qString str = "filename.perm.bin";str.StartsWith("file"); // truestr.StartsWith("name"); // false
EndsWith
bool EndsWith(const char* text, int length = -1);
Example:
qString str = "filename.perm.bin";str.EndsWith(".bin"); // truestr.EndsWith(".perm"); // false
Trim
qString Trim();
Example:
qString str = " test1234 ";str.Trim(); // "test1234"
MakeLower
void MakeLower();
Example:
qString str = "abc123DEF";str.MakeLower(); // str -> "abc123def"
MakeUpper
void MakeUpper();
Example:
qString str = "abc123DEF";str.MakeUpper(); // str -> "ABC123DEF"
ToLower
qString ToLower();
Example:
qString str = "abc123DEF";str.ToLower(); // "abc123def"
ToUpper
qString ToUpper();
Example:
qString str = "abc123DEF";str.ToUpper(); // "ABC123DEF"
GetFilePath
qString GetFilePath();
Example:
qString str = "some/path/to/filename.bin";str.GetFilePath(); // "some/path/to"
GetFilePathWithoutExtension
qString GetFilePathWithoutExtension();
Example:
qString str = "some/path/to/filename.bin";str.GetFilePathWithoutExtension(); // "some/path/to/filename"
GetFilename
qString GetFilename();
Example:
qString str = "some/path/to/filename.bin";str.GetFilename(); // "filename.bin"
GetFilenameWithoutExtension
qString GetFilenameWithoutExtension();
Example:
qString str = "some/path/to/filename.bin";str.GetFilenameWithoutExtension(); // "filename"