Match beginning of two strings
Jim Richardson
warlock at eskimo.com
Sun Aug 3 20:48:56 EDT 2003
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Sun, 3 Aug 2003 12:44:59 -0600,
Andrew Dalke <adalke at mindspring.com> wrote:
> 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.
>
Ah, I hadn't considered that.
> 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
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
iD8DBQE/La14d90bcYOAWPYRApsqAJ9OW1jCViH/ytTMwpMv/TtTo9Q0BwCg2/Hn
R41XPXwJUhQYvCBnrqRMqLY=
=arqM
-----END PGP SIGNATURE-----
--
Jim Richardson http://www.eskimo.com/~warlock
Linux, because eventually, you grow up enough to be trusted with a fork()
More information about the Python-list
mailing list