Easy3D 2.6.1
|
String manipulation utilities. More...
Functions | |
void | split (const std::string &in, char separator, std::vector< std::string > &out, bool skip_empty_fields=true) |
Splits a string into parts. | |
bool | split (const std::string &in, char separator, std::string &left, std::string &right) |
Splits a string into two parts. | |
std::string | join (const std::vector< std::string > &in, char separator) |
Join multiple strings. | |
std::string | join (const std::vector< std::string > &in, const std::string &separator) |
Join multiple strings. | |
void | replace (std::string &in, const std::string &old_substr, const std::string &new_substr) |
Replaces the old sub-string by a new sub-string. | |
std::string | to_lowercase (const std::string &s) |
Converts a string to lowercase. | |
std::string | to_uppercase (const std::string &s) |
Converts a string to uppercase. | |
std::string | quote (const std::string &s, char quotes='\"') |
Adds quotes to a string. | |
bool | starts_with (const std::string &haystack, const std::string &needle) |
Checks if a string starts with a substring. | |
bool | ends_with (const std::string &haystack, const std::string &needle) |
Checks if a string ends with a substring. | |
std::string | to_string (int value, int width, char fill='0') |
Converts an integer value to a string of a desired length. | |
std::string | printf (const char *format,...) |
void | appendf (std::string &dst, const char *format,...) |
Appends the resulting string to a supplied string. | |
std::string | current_time () |
Gets the time string, e.g., "Fri Jan 09 11:39:32 2015". | |
std::string | current_time_detailed () |
Gets the detailed current time as a string, e.g., "2024-10-24-17-41-16-753". | |
std::string | time (double time, int num_digits=1) |
Converts time (in millisecond) into a string with the most suitable/readable unit. The result will look like e.g., 88ms, 2.3s, 1.7m, 0.1h. | |
std::wstring | to_wstring (const std::string &str) |
Converts from std::string to std::wstring. | |
std::string | from_wstring (const std::wstring &wstr) |
Converts from std::wstring to std::string. | |
std::string | to_string (char c) |
Creates a one char string. | |
String manipulation utilities.
std::string current_time_detailed | ( | ) |
Gets the detailed current time as a string, e.g., "2024-10-24-17-41-16-753".
Different from current_time(), this method also includes the millisecond part.
bool ends_with | ( | const std::string & | haystack, |
const std::string & | needle ) |
Checks if a string ends with a substring.
[in] | haystack | the input string |
[in] | needle | the substring to check |
true
if haystack
ends with needle
, false
otherwise. std::string join | ( | const std::vector< std::string > & | in, |
char | separator ) |
Join multiple strings.
Joins all the strings in list in
into a single string with each element separated by the given separator
character.
[in] | in | the list of strings to join |
[in] | separator | the separator character |
std::string join | ( | const std::vector< std::string > & | in, |
const std::string & | separator ) |
Join multiple strings.
Joins all the strings in list in
into a single string with each element separated by the given separator
string.
[in] | in | the list of strings to join |
[in] | separator | the separator string (can be an empty string) |
std::string printf | ( | const char * | format, |
... ) |
Return a C++ string and work like printf.
std::string quote | ( | const std::string & | s, |
char | quotes = '\"' ) |
Adds quotes to a string.
Adds character quote
at the beginning and the end of string s
and returns the resulting string.
[in] | s | the string to quote |
[in] | quotes | the quoting char (default is '"') |
bool split | ( | const std::string & | in, |
char | separator, | ||
std::string & | left, | ||
std::string & | right ) |
Splits a string into two parts.
[in] | in | the input string to split |
[in] | separator | the separator character |
[in] | left | the part of the input string on the left of the separator or the empty string if the separator did not appear in the input string |
[in] | right | the right of the input string on the left of the separator or the empty string if the separator did not appear in the input string |
true | if the separator was found in the input string |
false | otherwise |
void split | ( | const std::string & | in, |
char | separator, | ||
std::vector< std::string > & | out, | ||
bool | skip_empty_fields = true ) |
Splits a string into parts.
Splits the string in
into a list of substrings out
wherever separator
occurs.
[in] | in | the input string to split |
[in] | separator | the separator character |
[in] | out | the resulting list of substrings |
[in] | skip_empty_fields | specifies whether empty parts should be ignored and not stored in list out (this is true by default). |
bool starts_with | ( | const std::string & | haystack, |
const std::string & | needle ) |
Checks if a string starts with a substring.
[in] | haystack | the input string |
[in] | needle | the substring to check |
true
if haystack
starts with needle
, false
otherwise. std::string to_lowercase | ( | const std::string & | s | ) |
Converts a string to lowercase.
The conversion is done in place in the string s
.
[in,out] | s | The string to convert |
|
inline |
Creates a one char string.
[in] | c | the character to convert to a string |
c
std::string to_string | ( | int | value, |
int | width, | ||
char | fill = '0' ) |
Converts an integer value
to a string of a desired length.
Different from the std::to_string(), this method results in a fixed-width string by filling the missing parts with character fill
.
std::string to_uppercase | ( | const std::string & | s | ) |
Converts a string to uppercase.
The conversion is done in place in the string s
.
[in,out] | s | The string to convert |