Re: Is there a way to use variables in a substring?
Posted in 1999
joel_anderson@prosolution.com wrote: > I am writing a stored procedure that will need to check each > character in a string. Here is a snippit of code: > . . . > DEFINE myChar CHAR(1); > DEFINE i INTEGER; > FOR i IN (1 TO myStringLen) > LET myChar = myString[i,i]; > IF myChar = "A" THEN > myString[i,i] = "a"; > END IF > END FOR; > . . . > > I get a syntax error on [i,i]. So you know the answer - NO. > If I replace the [i,i] with [1,1] it passes the syntax check. > Is there another way to do this? I am running on Informix 7.3. Thanks for mentioning the version - there is a concrete YES answer that can be given to you. There's a SUBSTR function you can use to do substring operations - check the manual for the details. If you were using any other version, the answer would have been NO unless you somehow write the substring function yourself. In your particular case, you could also repeatedly chop off the first character and then shift the rest of the string down one place - slow but workable even in older versions of Informix. -- Jonathan Leffler (jleffler@informix.com, jleffler@earthlink.net) Guardian of DBD::Informix v0.60 -- see http://www.perl.com/CPAN #include <disclaimer.h>