"MIDRANGE-L" <midrange-l-bounces@xxxxxxxxxxxx> wrote on 02/14/2017
09:41:23 AM:
API? Not that I'm aware of, but someone please surprise me!
On Tue, Feb 14, 2017 at 9:14 AM, David Gibbs <david@xxxxxxxxxxxx> wrote:
Folks:
Does anyone know if there is an API that will take text and return it
formatted to be used as a command parameter?
For instance: if I provide the text: This is 'text' for a description
It would return: This is ''text'' for a description
I did it with a couple of general utility type service procedures
-- which can also be called from CL, if needed.
*========================================================================*
* This procedure returns the supplied string as a single-quoted string *
* with any imbedded single-quotes appropriately doubled. *
*========================================================================*
dcl-proc GenUtl_MakeQuotedString export;
dcl-pi *n varchar(4096) rtnparm;
pString varchar(3000) const;
end-pi;
return ( ''''
+ GenUtl_ScanAndReplace('''': %trimr(pString): '''''')
+ '''' ); // return resulting entry
end-proc;
* ============================================================== *
* Find all occurrences of "needle" in the "haystack" and replace *
* them with the "straw" returning the "newhaystack". *
* ============================================================== *
dcl-proc GenUtl_ScanAndReplace export;
dcl-pi *n varchar(65535) rtnparm;
Needle varchar(32767) const;
Haystack varchar(65535) const;
Straw varchar(32767) const;
end-pi;
dcl-s NewHaystack varchar(65535);
dcl-s Posn packed(5:0);
NewHaystack = Haystack;
Posn = %scan(Needle: NewHaystack);
dow (Posn > *zero);
NewHaystack = %replace(Straw: NewHaystack: Posn: %len(Needle));
if ((Posn + %len(Straw)) <= %len(NewHaystack));
Posn = %scan(Needle: NewHaystack: Posn + %len(Straw));
else;
Posn = *zero;
endif;
enddo;
return NewHaystack; // return result to caller
end-proc;
Sincerely,
Dave Clark
As an Amazon Associate we earn from qualifying purchases.