bool starts_with(const char *txt, const char *target) { if (txt == nullptr && target == nullptr) return true; if (txt == nullptr || target == nullptr) return false; return strstr(txt, target) == txt; }
Programming Tips - C/C++ starts_with() function for plain strings
Date: 2025apr3
Language: C/C++
Keywords: startsWith
Q. C/C++ starts_with() function for plain strings
A. It can be done with the strstr() standard function.