Re: upper() - NOT the usual FAQ :-)
Posted in 1997
} }If only! :-( } }>From: Douglas Wilson <dgwilson@gte.net> }>Date: 15 May 1997 16:20:16 GMT }>X-Informix-List-Id: <news.37944> }> }>Richard Thomas wrote: }> }>> FOR i = 1 TO l }>> IF str[1,1] BETWEEN "a" AND "z" THEN }>> IF str[1,1] = 'a' THEN }>> LET retstr = retstr || 'A'; }>> ELIF str[1,1] = 'b' THEN }>> LET retstr = retstr || 'B'; }> }>I'm not an expert on stored procedures, but shouldn't the }>str[] variables be 'str[i,1]', not 'str[1,1]'? } }No, on two counts. } }First, the substring notation uses [start,end=1] not [start,len], so the }more correct notation would be str[i,i] or, preferably, just str[i]. } }Secondly, SPL is brain-dead. It does not allow variables in substring }expressions. So the notation using [i] doesn't work at all -- syntax }error. } }Why else do you think these functions are so utterly ghastly? If we could }do arbitrary substringing with variables, then life would be one heck of }a lot easier: } }LET lower = "abcdefghijklmnopqrstuvwxyz"; }LET upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; } }FOR i = 1 TO LENGTH(str) } LET n = index(lower, str[i]); } IF n != 0 THEN } LET str[i] = upper[n]; } END IF }END FOR } }If only!!! :-((( } }Yours, }Jonathan Leffler (johnl@informix.com) #include <disclaimer.h> } Hi folks, me again! The question I originally asked was why this procedure returned only the first character of the expected output, but the ensuing discussion got sidetracked onto why you can't have variable subscripts in SPL!! If you have any ideas why the upper function I posted the other week (check it out in the archives or email me for a copy if you think you can help) PLEASE HELP. (Sorry, didn't mean to shout). If this procedure doesn't work, why is it in the IIUG archive (BTW, there is another 'upper' procedure in there that DOES use variables in subscripts - if johnl et al are correct, as I'm sure they are, then that one is never going to work!!). Just re-read the above, and it sounds like I'm a bit 'annoyed' - don't take it that way :-) Cheers, Richard.