Focal Point Banner
Community Center Education Summit Technical Support User Groups
Let's Get Social!

Facebook Twitter LinkedIn YouTube
Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     Replacing multiple occurences of a value with another within a string
Go
New
Search
Notify
Tools
Reply
  
Replacing multiple occurences of a value with another within a string
 Login/Join
 
Member
posted
Is there an easy way in focus to replace multiple occurrences of a string within one string ?

Here's what I want to do :

From an alpha field, I want to define another one that replaces all spaces in the field with " ".

How can I achieve this ?
 
Posts: 21 | Registered: January 27, 2004Reply With QuoteReport This Post
Platinum Member
posted Hide Post
You can use CTRAN subroutine to translate one character to another (not string)


-SET &STRING = 'AB CD EF' ;
-SET &STRING = CTRAN(&STRING.LENGTH, &STRING, 32, 95, &STRING);

For a unique string replacement with known position, WebFOCUS also has the OVRLAY subroutine .

Regards,
Mikel

This message has been edited. Last edited by: <Mabel>,
 
Posts: 173 | Location: Madrid, Spain | Registered: May 09, 2003Reply With QuoteReport This Post
Member
posted Hide Post
Yes, I know that, but this doesn't help me with my issue.
 
Posts: 21 | Registered: January 27, 2004Reply With QuoteReport This Post
Platinum Member
posted Hide Post
Only available in MAINTAIN, STRAN function allows substitution of substrings.


MAINTAIN FILE CAR
MODULE IMPORT (MNTUWS);
COMPUTE STRING1/A10 = 'AB CD EF' ;
COMPUTE SUBSTR1/A1 = ' ' ;
COMPUTE SUBSTR2/A2 = 'XXX' ;
COMPUTE STRING2/A20 = STRAN(STRING1, SUBSTR1, SUBSTR2) ;
TYPE "OLD STRING: TYPE "NEW STRING: END
-RUN

-* Output:
-* OLD STRING: AB CD EF
-* NEW STRING: ABXXCDXXEFXXXX
Regards,
Mikel

This message has been edited. Last edited by: <Mabel>,
 
Posts: 173 | Location: Madrid, Spain | Registered: May 09, 2003Reply With QuoteReport This Post
<Pietro De Santis>
posted
Too bad you haven't moved to WebFOCUS 5.2 yet, as there's a new function called SQUEEZ that will "reduce multiple contiguous spaces within a character string to a single space".

Cheers,

Pietro.
 
Reply With QuoteReport This Post
Platinum Member
posted Hide Post
I have a similar issue with jif26. I need to replace any occurances of < with < and > with >

OVRLAY works but you need to loop if there are more than 1 occurances of the string.

Is there an easier way? Single pass?

Before: abc<123>def>ghi
After: abc<123>def>ghi

Thanks,


Dev: WebFOCUS 7.6.10, Data Migrator 7.6.10
QA: WebFOCUS 7.6.10, Data Migrator 7.6.10
Prod: WebFOCUS 7.6.2, Data Migrator 7.6.8
Windows 2K3, Tomcat 5.5.17, IIS 6
Usage: HTML, PDF, Excel, Self-serve, BID and MRE
 
Posts: 197 | Location: Roseville, CA | Registered: January 24, 2005Reply With QuoteReport This Post
Virtuoso
posted Hide Post
Use STRREP.
It's useful to know what area you are using, e.g. TABLE,DM,MAINTAIN.

Change < to & lt; and > to & gt;
-SET &STRING='abc<123>def>ghi';
-SET &ASTRING = STRREP(&STRING.LENGTH,&STRING,1,'<',4,'&|lt;',&STRING.LENGTH*2,'A&STRING.LENGTH*2');
-SET &BSTRING = STRREP(&ASTRING.LENGTH,&ASTRING,1,'>',4,'&|gt;',&ASTRING.LENGTH*2,'A&ASTRING.LENGTH*2');
-TYPE &BSTRING


Alan.
WF 7.705/8.007
 
Posts: 1451 | Location: Portugal | Registered: February 07, 2007Reply With QuoteReport This Post
Platinum Member
posted Hide Post
Hi Alan B,

I'm using TABLE and/or DEFINE. We have fields that have multiple occurance of these characters and we want them replaced.

Thanks,


Dev: WebFOCUS 7.6.10, Data Migrator 7.6.10
QA: WebFOCUS 7.6.10, Data Migrator 7.6.10
Prod: WebFOCUS 7.6.2, Data Migrator 7.6.8
Windows 2K3, Tomcat 5.5.17, IIS 6
Usage: HTML, PDF, Excel, Self-serve, BID and MRE
 
Posts: 197 | Location: Roseville, CA | Registered: January 24, 2005Reply With QuoteReport This Post
Virtuoso
posted Hide Post
Same difference really:
STRING/A20='abc<123>def>ghi';
ASTRING/A100V = STRREP(20,STRING,1,'<',4,'&|lt;',100,ASTRING);
BSTRING/A100V = STRREP(LENV(ASTRING,'I2'),ASTRING,1,'>',4,'&|gt;',100,BSTRING);


Alan.
WF 7.705/8.007
 
Posts: 1451 | Location: Portugal | Registered: February 07, 2007Reply With QuoteReport This Post
Platinum Member
posted Hide Post
I tried the code below and it did not work:

DEFINE FILE CAR
STRING/A20='abc<123>def>ghi';
4,'&|lt;',100,ASTR);
ASTRING/A100V = STRREP(20,STRING,1,'<',4,'&|lt;',100,ASTRING);
BSTRING/A100V = STRREP(LENV(ASTRING,'I2'),ASTRING,1,'>',4,'&|gt;',100,BSTRING);
END

TABLE FILE CAR
PRINT
COUNTRY
STRING
ASTRING
BSTRING
END

Tried opening the DEFINE section in the physical view in Dev studio and when I click okay, I get: "Semicolons are not allowed" and won't allow me to save.


Dev: WebFOCUS 7.6.10, Data Migrator 7.6.10
QA: WebFOCUS 7.6.10, Data Migrator 7.6.10
Prod: WebFOCUS 7.6.2, Data Migrator 7.6.8
Windows 2K3, Tomcat 5.5.17, IIS 6
Usage: HTML, PDF, Excel, Self-serve, BID and MRE
 
Posts: 197 | Location: Roseville, CA | Registered: January 24, 2005Reply With QuoteReport This Post
Platinum Member
posted Hide Post
Correction:

DEFINE FILE CAR
STRING/A20='abc<123>def>ghi';
ASTRING/A100V = STRREP(20,STRING,1,'<',4,'&|lt;',100,ASTRING);
BSTRING/A100V = STRREP(LENV(ASTRING,'I2'),ASTRING,1,'>',4,'&|gt;',100,BSTRING);
END

TABLE FILE CAR
PRINT
COUNTRY
STRING
ASTRING
BSTRING
END


Dev: WebFOCUS 7.6.10, Data Migrator 7.6.10
QA: WebFOCUS 7.6.10, Data Migrator 7.6.10
Prod: WebFOCUS 7.6.2, Data Migrator 7.6.8
Windows 2K3, Tomcat 5.5.17, IIS 6
Usage: HTML, PDF, Excel, Self-serve, BID and MRE
 
Posts: 197 | Location: Roseville, CA | Registered: January 24, 2005Reply With QuoteReport This Post
Virtuoso
posted Hide Post
Dev studio opens the code as I wrote it, and it works as I tested it.

What error are you getting.


Alan.
WF 7.705/8.007
 
Posts: 1451 | Location: Portugal | Registered: February 07, 2007Reply With QuoteReport This Post
Platinum Member
posted Hide Post
I can open the code as using text editor in Dev studio. It is only when I use, not sure what you call it, the DEFINE gui and not do anything and click the OK button. I get "Semicolons not allowed.". If you need a screen shot of the message, I can send it to you.


Dev: WebFOCUS 7.6.10, Data Migrator 7.6.10
QA: WebFOCUS 7.6.10, Data Migrator 7.6.10
Prod: WebFOCUS 7.6.2, Data Migrator 7.6.8
Windows 2K3, Tomcat 5.5.17, IIS 6
Usage: HTML, PDF, Excel, Self-serve, BID and MRE
 
Posts: 197 | Location: Roseville, CA | Registered: January 24, 2005Reply With QuoteReport This Post
Virtuoso
posted Hide Post
That would be the DEFINE tool objecting to a semi colon in the DEFINE.

Not much you can do about that, use the text editor, temporarily remove the semi colons, work in the gui tool, and put back when you have finished.

Does the code itself run and produce correct results?


Alan.
WF 7.705/8.007
 
Posts: 1451 | Location: Portugal | Registered: February 07, 2007Reply With QuoteReport This Post
Platinum Member
posted Hide Post
Running the code below did not work. The strings < and > were not replaced.

DEFINE FILE CAR
STRING/A20='abc<123>def>ghi';
ASTRING/A100V = STRREP(20,STRING,1,'<',4,'&|lt;',100,ASTRING);
BSTRING/A100V = STRREP(LENV(ASTRING,'I2'),ASTRING,1,'>',4,'&|gt;',100,BSTRING);
END

TABLE FILE CAR
PRINT
COUNTRY
STRING
ASTRING
BSTRING
END


Dev: WebFOCUS 7.6.10, Data Migrator 7.6.10
QA: WebFOCUS 7.6.10, Data Migrator 7.6.10
Prod: WebFOCUS 7.6.2, Data Migrator 7.6.8
Windows 2K3, Tomcat 5.5.17, IIS 6
Usage: HTML, PDF, Excel, Self-serve, BID and MRE
 
Posts: 197 | Location: Roseville, CA | Registered: January 24, 2005Reply With QuoteReport This Post
Virtuoso
posted Hide Post
The strings will be replaced, but when you view it under HTML, the & lt; will show as < and the & gt; will show as >. Which is expected.

View source will show the difference.

If this is not what you want, please explain as your original message was a bit unclear.


Alan.
WF 7.705/8.007
 
Posts: 1451 | Location: Portugal | Registered: February 07, 2007Reply With QuoteReport This Post
Platinum Member
posted Hide Post
You are correct! This is what we need.

Thanks!


Dev: WebFOCUS 7.6.10, Data Migrator 7.6.10
QA: WebFOCUS 7.6.10, Data Migrator 7.6.10
Prod: WebFOCUS 7.6.2, Data Migrator 7.6.8
Windows 2K3, Tomcat 5.5.17, IIS 6
Usage: HTML, PDF, Excel, Self-serve, BID and MRE
 
Posts: 197 | Location: Roseville, CA | Registered: January 24, 2005Reply With QuoteReport This Post
  Powered by Social Strata  
 

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     Replacing multiple occurences of a value with another within a string

Copyright © 1996-2018 Information Builders, leaders in enterprise business intelligence.