[Gambas-user] Bug in split() ? (1.0.13)
Eilert
eilert-sprachen at ...221...
Wed Jan 18 10:45:22 CET 2006
I am not quite sure, folks, but this seems to be a bug in the Split()
function. Or didn't I understand how to use it? Anyway:
In my program, there are strings from a file indicating where and how
certain input elements of an input mask should appear. For example,
there is a "list" element (ComboBox) which has to display some items for
the user to click on.
This is what those strings look like:
item= mask:'*rau', opt:nocase, insert:'Frau', display:'weiblich'
item= mask:'*err', opt:nocase, insert:'Herr', display:'männlich'
This means, if you find "*rau", case-insensitive, display "weiblich". If
chosen by the user, insert "Frau" into the field.
Now, this function was meant to pick out the "display" command from the
string. I inserted a message.info, because it shows what goes wrong:
RIVATE FUNCTION MaskeLstDisplay(lst AS String) AS String
DIM lOpt AS NEW String[]
DIM lCom AS NEW String[]
DIM i AS Integer
DIM x$ AS String
lOpt = Split(lst, ",", "'") 'String nach Optionen aufteilen (Kommas)
'Kommando "display" suchen:
FOR i = 0 TO lOpt.Count - 1
lCom = Split(lOpt[i], ":", "'")
message.Info(lCom[0] & "--" & lCom[1])
IF String.LCase(Trim$(lCom[0])) = "display" THEN
x$ = Trim$(lCom[1])
IF String.Left(x$, 1) = "'" THEN x$ = String.Mid(x$, 2)
IF String.Right(x$, 1) = "'" THEN x$ = String.Left(x$,
String.Len(x$) - 1)
RETURN x$
END IF
NEXT
RETURN "?display-Angabe fehlt"
END
The line above the message.info includes "'" as an escape string. This
would mean you could use ":" within the strings without getting trouble.
If you feed the function with strings like above, you will see that the
last "'" will remain, whilest all other "'" are cut. In my program, this
function is called about 6 times, and sometimes (not reproduceably) the
Split() keeps garbage from previous calls. I've got "display" commands
with shorter strings, and sometimes character garbage and some "m nnl
ch" or so will remain at the end of the next string.
The point is, when you leave the Escape character away, everything runs
smoothly, it just leaves the "'" at the strings and doesn't care about them.
So, is this a bug or am I making a mistake?
Thanks for your hints.
Rolf
More information about the User
mailing list