3 ms·
since an empty string is '\0' then the index of the first occurency of an empty string (which is '\0') is 0 ;)
by gtroja 3y ago
since an empty string is '\0' then the index of the first occurency of an empty string (which is '\0') is 0 ;)
- flqn 3y agoDepends on your string representation. It's not unreasonable for an empty string to have no internal buffer allocated meaning it wouldn't even have a NUL terminator!
- not2b 3y agoOnly in C, other languages don't use null-terminated strings. A C++ std::string can contain a '\0' as the first character but still not be empty (though of course C++ code can also use C strings). But even if an empty string truly contains no data it will match at the very beginning, so it seems returning 0 is still consistent.