I know I can use regex matching with ~=
and that stridx(haystack, needle) == 0
does work, but if I just want to verify that one string starts with another, I don't want to waste resources checking the rest of the haystack, which stridx will do.
What's the fastest way to compare the beginning of the string? I have my own answer below, but I suspect it can be done even better, perhaps by not creating a temporary string but by directly indexing the two strings?