[Gambas-user] LIKE operator bug?

Benoit Minisini gambas at ...1...
Tue Sep 9 01:23:27 CEST 2008


On lundi 08 septembre 2008, Stefano Palmeri wrote:
> I've this code and I want to filter all not-digits from an
> alphanumeric string.
>
>
> PUBLIC SUB Main()
>
>   DIM sAllChars, sSingleChar, sFiltered AS String
>
>   sAllChars = "1,2,A,B,C,D,é,é,a,x,ç,5,7,G,°,§,$,&,£,1,2,3,4"
>
>   FOR EACH sSingleChar IN Split(sAllChars)
>
>     IF sSingleChar LIKE "[^0-9]" THEN
>       CONTINUE
>     ELSE
>       sFiltered = sFiltered & sSingleChar
>     ENDIF
>
>   NEXT
>
>   PRINT sFiltered
>
> END
>
>
> but the result is "12ééç57°§£1234". It seems that LIKE gets confused by
> some special chars. I don't know whether this is a bug or something else.
>
> My Gambas version is 2.7.0
>
> Saluti,
>
> Stefano Palmeri
>

LIKE only deals with ASCII characters, not with UTF-8 strings. In UTF-8 
strings, non ASCII-characters are written with several bytes, and so LIKE 
gets confused.

Regards,


-- 
Benoit Minisini




More information about the User mailing list