[Gambas-user] Catch NULL character

Benoît Minisini gambas at ...1...
Sat Mar 28 10:20:04 CET 2009


> CelticBhoy ha scritto:
> > What is wrong with this line :-
> >
> > IF sElement[iLoop] = NULL THEN sElement[iLoop] = "0"
> >
> > I want to catch a null character and change it to "0".
>
> You are using an array notation, ie, sElement[] designes an array of
> strings, each composed of many characters.
> Moreover, NULL is not the same as chr$(0), but refers to the null
> pointer (or an empty string), but this is different from C.
>
> if sElement is a simple string, and assuming iLoop goes from 1 to the
> length of the string, then you test like this:
>
>     if mid$(sElement, iLoop, 1)=chr$(0) then sElement=left$(1,iLoop-1) &
> "0" & mid$(sElement, iLoop+1)
>
> Note two things here: gambas does not have indexing of strings, like C.
> Use left$(), mid$() and so on is the way to analyze strings. This also
> means that you can not change a single char in a string, but you have to
> reconstruct the string itself.

Note that now in Gambas 3 you can do: 

Mid$(SomeString, X, 5) = AnotherString

Regards,

-- 
Benoît




More information about the User mailing list