Getting the actual length of a UTF-8 encoded std::string? July 28, 2023 by Tarik Count all first-bytes (the ones that don’t match 10xxxxxx). int len = 0; while (*s) len += (*s++ & 0xc0) != 0x80;