I know how to remove one or many spaces before the first word in a string in C, but I don't know in C++ (if there is a function by example).
My string is : " Hello" and I want to get "Hello". How can I do ?
I know how to remove one or many spaces before the first word in a string in C, but I don't know in C++ (if there is a function by example).
My string is : " Hello" and I want to get "Hello". How can I do ?
Use std::string::find_first_not_of(' ')
to get the index of the first non-whitespace character, then take the substring from there
Example:
std::string str = " Hello";
auto pos = str.find_first_not_of(' ');
auto Trimmed = str.substr(pos != std::string::npos ? pos : 0);
std::string TrimLeft(const std::string& str){
auto pos = str.find_first_not_of(' ');
return str.substr(pos != std::string::npos ? pos : 0);
}