Focal Point
convert double quote to "%22"

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

August 10, 2006, 12:11 PM
GreenspanDan
convert double quote to "%22"
i'm getting back a result set that has double quotes in it. for programatic reasons, i want to convert any double quotes to %22. how can i do this? i have no way of knowing in advance where the double quotes will appear or how many ther will be.


---------------------
WebFOCUS 7.6
August 10, 2006, 12:29 PM
susannah
Dan, i would suggest using the string functions in the manual 'Using Functions'
and there would be a number of ways to do it, depending on the nature of the end result you want.
if CTRAN would't work for you
then a loop of POSIT and OVRLAY would do the trick.
-s
Here's a quick table of some useful (well, u b the judge) bytvals for the CTRAN function
ASCII bytvals for ctran function 
 
AMPERSAND 38 DASH 45 APOSTROPHE 39 COMMA 44 QUOTE 34 PERIOD 46 PIPE 124 
SLASH 47 BLANK 32 PLUS 43 UNDER 95 LEFTBRKT 60 RIGHTBRKT 62 POUND 35 
LEFTPAR 40 RIGHTPAR 41 LEFTBRACE 91 RIGHTBRACE 93 NUMZERO 48 EQUAL 61 DOLLAR 36 
ASTERISK 42 UNDERSCORE 95 ZERO 48 EACUTE 233 


so your CTRAN would want to change a 34 (quote) to something friendlier, like a single quote 39 or a blank 32.
With a single CTRAN on a field, you can nuke all the " and make them something else, regardless of how many.

This message has been edited. Last edited by: susannah,




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
August 10, 2006, 12:33 PM
smiths
Give this a whirl...

  
-*--------------------------------------------------------------
-* Replace all double quotes with %22
-*--------------------------------------------------------------

-* String to replace
-SET &FIELD = '"abc"def"ghi"';

-* Get the field length
-SET &FIELD_LEN = &FIELD.LENGTH;


-* Initialize variables
-SET &NEWSTR = '';
-SET &IDX = 1;

-* Iterate through the entire string a character at a time
-REPEAT :END_DBL WHILE &IDX LE &FIELD_LEN;

-* Get the next character in the string
-SET &CHARACTER = SUBSTR(&FIELD_LEN, &FIELD, &IDX, 
-                 &IDX, 1, 'A1');

-* Append %22 if a double quote is found,
-* otherwise append the character
-SET &NEWSTR = IF &IDX EQ 1 THEN (IF &CHARACTER EQ '"'
-THEN '%22' ELSE &CHARACTER)
-ELSE          IF &CHARACTER EQ '"' THEN &NEWSTR | '%22'
-ELSE          &NEWSTR | &CHARACTER;

-* Advance to the next character
-SET &IDX = &IDX + 1;

-:END_DBL
-*--------------------------------------------------------------

-TYPE FIELD : (&FIELD)
-TYPE NEWSTR: (&NEWSTR)


Regards,
Sean


------------------------------------------------------------------------
PROD: WebFOCUS 7.6.2 on Unix AIX/Tomcat/Servlet Mode
TEST: WebFOCUS 7.6.2 on Unix AIX/Tomcat/Servlet Mode
August 11, 2006, 03:21 AM
Tony A
Dan,

With release 7.x there is a new function called STRREP that should foot the bill precisely. It has been reported that it also works in 5.3.2 upwards but you would have to check. If you going to 7.1.x imminently then it would be worth using it.

From the help screens -

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

where:

inlength - Numeric
Is the number of characters in the input string.

instring - Alphanumeric
Is the input string.

searchlength - Numeric
Is the number of characters in the (shorter length) string to be replaced.

searchstring - Alphanumeric
Is the character string to be replaced.

replength - Numeric
Is the number of characters in the replacement string. Must be zero (0) or greater.

repstring - Alphanumeric
Is the replacement string (alphanumeric). Ignored if replength is zero (0).

outlength - Numeric
Is the number of characters in the resulting output string. Must be 1 or greater.

outstring - Alphanumeric
Is the resulting output string after all replacements and padding.


T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
August 11, 2006, 05:05 AM
Tony A
Using Sean's example -

-SET &FIELD = '"abc"def"ghi"';
-SET &NewFld = STRREP (&FIELD.LENGTH, '&FIELD.EVAL', 1, '"', 3, '%22', 40, 'A40');

-TYPE &FIELD
-TYPE &NewFld


Gives the output

"abc"def"ghi"
%22abc%22def%22ghi%22

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
August 11, 2006, 10:16 AM
susannah
STRREP must be a much-needed new function in 7
7 rocks!!




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
August 11, 2006, 12:11 PM
smiths
Tony,

Nice to see that IBI has introduced a function to handle this job!

I'm stuck with 5.2.x for now, so I'll have to keep the hand-coded method until we move to 7.

Thanks,
Sean


------------------------------------------------------------------------
PROD: WebFOCUS 7.6.2 on Unix AIX/Tomcat/Servlet Mode
TEST: WebFOCUS 7.6.2 on Unix AIX/Tomcat/Servlet Mode
August 11, 2006, 01:07 PM
GreenspanDan
ah ha! that STRREP function would have saved me a lot of work over the last two days. byebye 50 lines of code.

This message has been edited. Last edited by: GreenspanDan,
August 11, 2006, 03:57 PM
Glenda
Must the replacement value eq %22? Are the double quotes a result of saving or holding the file in format lotus?


Glenda

In FOCUS Since 1990
Production 8.2 Windows