A switch
statement is not really meant to be used the way you're trying to use it; It's meant for returning simple values and not for more complicated statements, like variable assignments. I'd guess that the behavior you're seeing is probably just a byproduct of the specific implementation of the function.
Instead, you can either use the case-statement
or rearrange your switch
so that it is only used to return simple values.
//Your code changed to use a case-statement
Local StringVar inString := "X12y1023" ;
Local StringVar outString;
Local NumberVar i :=1;
While i <= Length(inString)
Do (
Local StringVar inC := mid(inString, i, 1);
Local StringVar outC;
Select inC
Case "1" : outC:="!"
Case "2" : outC:="Z"
Case "3" : outC:="E"
Case "0" : outC:="O"
Default : outC:=inC;
outString := outString + outC;
i := i+1;
);
outString;
Or
//Your code rearranged to use switch as intended
Local StringVar inString := "X12y1023" ;
Local StringVar outString;
Local NumberVar i :=1;
While i <= Length(inString)
Do (
Local StringVar inC := mid(inString, i, 1);
outString := outString +
switch(
inC = "1", "!",
inC = "2", "Z",
inC = "3", "E",
inC = "0", "O",
True, inC);
i := i+1;
);
outString;