Lets say I have
std::wstring str(L" abc");
The contents of the string could be arbitrary.
How can I find the first character that is not whitespace in that string, i.e. in this case the position of the 'a'?
use [std::basic_string::find_first_not_of][1]
function
std::wstring::size_type pos = str.find_first_not_of(' ');
pos is 3
Update: to find any other chars
const wstring delims(L" \t,.;");
std::wstring::size_type pos = str.find_first_not_of(delims);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With