Re: String concatenation in OnLine stored procedure - REPOSTED
Posted in 1997
Thanks for everyones replies, however, I have no TRIM() function
available within OnLine 5, unless it's called something else.
I also seem to be stumped because I can't put any sort of variable
into a substring specification, so str[1,LENGTH(str)] constructs aren't
possible either.
I seem to be stuck with:
i = LENGTH(str1)
IF i = 1 THEN
str1 = str1[1,1] || str2
ELIF i = 2 THEN
str1 = str1[1,2] || str2
ELIF i = 3 THEN
str1 = str1[1,3] || str2
etc...
Ho Hum.
> Corrected and Reposted!
>
> >How would one achieve what Andy wants to achieve using TRIM ?
>
> --* PROCEDURE FOR inserting a string INTO a source string AT pos'th
> position
> --* DROP PROCEDURE ins_str;
> CREATE PROCEDURE ins_str(sourcestr CHAR(20), insertstr CHAR(30),pos
> smallint)
> RETURNING CHAR(60);> DEFINE p_ret_val CHAR(10);
> DEFINE p_idx SMALLINT;
> DEFINE p_trim CHAR(1);
> DEFINE p_len INTEGER;
> DEFINE p_fwd_str CHAR(30);
>
> LET p_fwd_str = sourcestr[1,1];
> LET p_ret_val = " ";
> LET p_trim = sourcestr[1,1];
> LET p_len = LENGTH(sourcestr);
> FOR p_idx = 1 TO p_len
> LET p_ret_val = TRIM(LEADING p_trim[1,1] FROM sourcestr) ;
> LET p_trim = p_ret_val[1];
> LET sourcestr = p_ret_val;
> IF p_idx = pos - 1 THEN --* CORRECTED!!
> LET p_fwd_str = TRIM(p_fwd_str) || TRIM(insertstr) ;
> EXIT FOR;
> END IF
> LET p_fwd_str = TRIM(p_fwd_str) || p_trim;
> END FOR
> RETURN TRIM(p_fwd_str) || TRIM(sourcestr);
> END PROCEDURE;
>
> --* Test it!
> EXECUTE PROCEDURE ins_str("GETINSERTED","(I GOT INSERTED)",3) ;> Hope this helps you !
>
> Harinath Venkata
> New York.
> --* Standard disclaimers apply *--------------
>
>
> On Mon, 28 Jul 1997 14:07:04 -0700 (PDT) bfldc2@bfl.soft.net (BAZIC
> Project Group) writes:
> >>How would one achieve what Andy wants to achieve using TRIM ?
> >
> >Thanks in advance,
> > Vinitha
> >
> >> Use TRIM function instead of CLIPPED!
> >>
> >> Hope this helps!
> >>
> >>
> >> HARINATH VENKATA
> >>
> >>
> >> On Fri, 25 Jul 97 14:34:17 GMT andy@kontron.demon.co.uk (andy
> >lennard)
> >> writes:
> >> }Hi,
> >> }Hope you can help me.
> >> }I'm trying to concatenate strings in a stored procedure
> >> }(Online 5.03, SunOS 4.1.3) and have found the || operator but
> >> }how do you do :
> >> }
> >> } LET len_str = LENGTH(str1)
> >> } LET str = str[1,len_str] || str2
> >> }
> >> }It won't let me put a variable within the character substring
> >> }specification. [1,3], for example, is fine, but a variable, no!
> >> }Alas, there is no CLIPPED operator either.
> >> }
> >> }Any and all suggestions gratefully received. Thankyou.
> >> }
> >> }Andy.
> >> }
> >> }--
> >> }Andy Lennard andy@kontron.demon.co.uk
> >> }
> >> }
> >>
> >
> >
>
--
Andy Lennard andy@kontron.demon.co.uk