Match beginning of two strings

Andrew Dalke adalke at mindspring.com
Sun Aug 3 14:44:59 EDT 2003


Jim Richardson:
> Why bother finding out which one is the shorter? if you try the compare,
> and you run out of the other to compare to, then by default, it's not
> the same :)

Because I wasn't sure if the strings had embedded NULs in them.
Python strings allow those.

Otherwise something like this would work

char *s1, *s2 = ... the strings from Python
char *s = s1;
while ( *s1 && (*s1++ == *s2++))
    ;
return the string from s->s1, or just the size s1-s.

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list