Focal Point
Search and Replace

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/6511006461

April 21, 2006, 06:57 PM
Govind Jujare
Search and Replace
Has anybody been able to code a generic-search-and-replace function ?

-*
-* Replace occurances of P2 in P1 with P3
-*
DEFINE FUNCTION SREPLACE/A255(P1 A255, P2 A255, P3 A255)
...
...
END

I was about to implement it but fell short of how finding out syntax to
write a loop in webfocus. I dont see in manuals how to write a loop. Any
ideas ? I see that the DM kind of GOTO is not supported in functions.


WebFOCUS 5.3.3 MRE - Solaris - Sun Web Server - Weblogic
April 21, 2006, 07:53 PM
Mikel
Working on WebFOCUS 7, we can use STRREP function:

STRREP Function: Replacing Character Strings
(documented as 7.1.3 new feature)

Simple D.M. Example tested with WF 7.1.0 & 7.1.1:
-SET &V1 = 'a OR b OR c OR d OR e' ;
-SET &V2 = STRREP(&V1.LENGTH, &V1, 4, ' OR ', 1, ',', &V1.LENGTH, 'A&V1.LENGTH');
-TYPE V1= &V1
-TYPE V2= &V2

Output:
V1= a OR b OR c OR d OR e 
V2= a,b,c,d,e

Regards,
Mikel


WebFOCUS 8.1.05, 8.2.01
April 21, 2006, 08:00 PM
Mikel
STRREP Function: Replacing Character Strings
Documented as 7.1.3 new feature but working with 7.1.0 and 7.1.1 (?)

Syntax: How to Replace Character Strings

STRREP (inlength, instring, searchlength, searchstring, replength, repstring, outlength, outstring)

Regards,
Mikel


WebFOCUS 8.1.05, 8.2.01
April 21, 2006, 11:34 PM
Govind Jujare
I see. I am on 5.3.3.

I guess I will try javascript. Thx.


WebFOCUS 5.3.3 MRE - Solaris - Sun Web Server - Weblogic
April 27, 2006, 02:03 AM
Govind Jujare
I tested it just now on 5.3.3 and yes it worked. Thx for the tip. That helped me avoid a whole bunch of coding.


WebFOCUS 5.3.3 MRE - Solaris - Sun Web Server - Weblogic
June 01, 2006, 11:55 PM
<Antony Gubert>
Hi,

I think that the above function work only when you know the length of each value of the string. What is the solution if I get a string as input and want to apply find and replace method. Please let me know.

Thanks
June 02, 2006, 12:12 AM
Govind Jujare
How about using LENGTH function to first find lengths ?

-SET &V1 = 'ABCDEFGH';
-SET &L1 = &V1.LENGTH;

This message has been edited. Last edited by: Govind Jujare,


WebFOCUS 5.3.3 MRE - Solaris - Sun Web Server - Weblogic
June 02, 2006, 06:44 AM
<JG>
What's actually interseting about the example is that the output is wrong.

When you use FTOA it left justifies the text it creates.

Also the substitution is invalid because all of the columns are not
the same number of characters, so you end up with
 
      USD 123456
      USD 12345  


If it was correctly justified it would look like

 
      USD 123456
       USD 12345  



A floating $ is wrong, the example would only work if the format of the field
is Dt.sN