[Gambas-user] pb changing a char in a string
Doriano Blengino
doriano.blengino at ...1909...
Wed Aug 19 19:32:07 CEST 2009
Jean-Yves F. Barbier ha scritto:
> Hi list,
>
> I've got a global flag that is a string of 2 chars.
>
> In some procs, I've to change the 1st char, but I've got an error:
>
> Global (class) => EXPORT
> CREATE STATIC
> PUBLIC lastSelection AS String = "DU"
>
> monitor => Global.lastSelection = "DU"
> prout, prout, prout...
> monitor => Global.lastSelection = "TG"
>
> proc => Global.last.Selection[1] = "W"
>
> gives me a "not an object" error in proc!??
> why am I not able to access one char into a string?
>
> JY
>
Dear Jean-Yves,
basic is not stupid C. If C doesn't distinguish between strings and
arrays, well, many others do, including gambas.
I can't remember well, but I think that you can't change a single
character in a string - you must use MID$() and & to extract the left
part, add the changed part, and add the last part. Something like:
global.last.selection = "W" & mid(global.last.selection,2)
(there is no left part to preserve) ...but read about mid$(), I am not sure.
Perhaps you are thinking that gambas is stupid, but this way you can
collect a single character, or many, while in C you use two different
methods ([...] access and strcat() and so on).
Regards,
Doriano
More information about the User
mailing list