On second thoughts JD, can’t use strlen or sqlite3_value_bytes in case values(1) contains more than a single unicode character. This looks OK.
# define CHARLEN(x) !(x & 128) ? 1 : (x & 16 ? 4 : (x & 32 ? 3 : 2)) char *c = (char *)sqlite3_value_text(values[0]); char *Sep = (char *)sqlite3_value_text(values[1]); int Count=0, Len, SepLen = CHARLEN(*Sep); while (*c) { if ((Len = CHARLEN(*c)) == SepLen && memcmp(c, Sep, Len)==0) Count++; // at start of Sep c += Len; } sqlite3_result_int(ctx, Count); _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users