× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



"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.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.