PxPlus User Forum

Twitter Twitter Twitter

Author Topic: detect embedded quotes  (Read 2366 times)

Lawrence_Leavell

  • Silver Member
  • ***
  • Posts: 49
    • View Profile
detect embedded quotes
« on: January 25, 2019, 01:32:34 PM »
Does someone have a decent program to identify the location within a string of embedded quotes?
We keep having an issue with operators typing embedded quotes that drives out system nuts.

Joseph Heim

  • New Member
  • *
  • Posts: 2
    • View Profile
Re: detect embedded quotes
« Reply #1 on: January 25, 2019, 03:45:13 PM »
May be sub() function ?

Mike King

  • Diamond Member
  • *****
  • Posts: 3811
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: detect embedded quotes
« Reply #2 on: January 25, 2019, 05:45:04 PM »
Lawrence,

You can use the POS function to detect the double quotes as in:

(Assuming the field is in X$)...

IF POS(QUO=X$)<>0 MSGBOX "Invalid quote character in data"

Alternatively you could change them to something else using the SUB function as in:

X$= SUB (X$, QUO, "'")

(That's a single apostrophe inside double quotes)

If you happen to be using the standard Windows ISO character set you might try replacing the quote with something like $A8$ which would generally convert like this:

"Quoted String"   -> ¨Quoted String¨
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com

Lawrence_Leavell

  • Silver Member
  • ***
  • Posts: 49
    • View Profile
Re: detect embedded quotes
« Reply #3 on: January 29, 2019, 12:37:15 PM »
This software generates complete screens, such as:
@(22,0),"** ADDITIONAL FORM / WINDOW (A) **",@(4,1),"FORM NUMBER",@(23,1),"SPECI
AL EDIT INDICATOR",@(49,1),"STEP NO",@(62,1),"RECORD TYPE",@(4,2),"=============
========",@(27,2),"DEFINE A STANDARD PROCESS",@(54,2),"=====================",@(
24,4),"ADDITIONAL FORM",@(12,6),"CLEAR PREVIOUS FORM COMPLETELY? (Y/N/W=WINDOW)"
,@(18,8),"STARTING POSITION",@(40,8),"STARTING LINE",@(18,9),"ENDING POSITION",@
(40,9),"ENDING LINE",@(9,12),"==================================================
==========",@(9,13),"PROVIDED THE LOGICAL CONDITIONS ARE MET, THIS  FUNCTION WIL
L",@(9,14),"ALLOW AN  ADDITIONAL FORM TO BE RUN  OR  A POP-UP 4GL WINDOW",@(9,15
),"FORM TO BE CALLED.   TO TRANSFER DATA FROM  ONE FORM  TO THE",@(9,16),"NEXT,
EACH RECEIVING ELEMENT MUST BE DEFINED WITH MULTI-FORM",@(9,17),"INDICATOR SET T
O "A", AND  THE SENDING AND RECEIVING ELEMENT",@(9,18),"NAMES MUST BE IDENTICAL.
  DATA MAY BE PASSED BACK AND FORTH",@(9,19),"BETWEEN ANY FORM AND A POP-UP 4GL
WINDOW IN THIS MANNER.",@(9,20),"===============================================
=============",@(68,21),"CORRECT?",@(0,22),"

The issue is the "A" which is not double quoted.

EVa

  • Gold Member
  • ****
  • Posts: 54
    • View Profile
    • EDIAS
Re: detect embedded quotes
« Reply #4 on: January 30, 2019, 03:54:55 AM »
When you compile a text with missing quotes, TCB(43) will tell you where the problem happened.  For example:

0010 SETERR OOPS
0020 LET x$="INDICATOR SET TO "+QUO+"A"+QUO+", AND  THE SENDING AND RECEIVING ELEMENT"
0030 LET y$=CPL("X$="+QUO+x$+QUO)
0040 PRINT "All is well"; STOP
0050 OOPS: LET position=TCB(43); PRINT "Error",ERR
0060 PRINT "Right here: ",x$(position-4) ! 4 = length of (X$=") in CPL()
-:run
Error 20
Right here: "A", AND  THE SENDING AND RECEIVING ELEMENT

-Eric-

Mike King

  • Diamond Member
  • *****
  • Posts: 3811
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: detect embedded quotes
« Reply #5 on: January 30, 2019, 02:57:11 PM »
This looks like your input itself is bad.  You should not have quotes within quotes -- no language I know of supports this without either doubling up on the quotes or providing some form of Escape before the quote. 

I would suggest you contact whoever gave you this input to process and discuss this with them as it would be better if the software that generated the string replaced all quotes within the string with two quotes.

Now as for your specific example, if the strings you are processing are similar you may be able to identify the quotes around the string literals as they are either preceded by ), or followed by ,@(.  This may allow you to do the following KLUDGE.

Assuming the string is in X$

X1$=X$+",@()" ! Append dummy position
X1$=SUB(X1$, QUO+",@(", $00$+",@(") ! Replace ending quote with $00$
X1$=SUB(X1$, "),"+QUO, "),"+$00$) ! Replace leading quote with $00$
X1$=SUB(X1$, QUO, QUO+QUO) ! Double up all remaining quotes
X1$=SUB(X1$,$00$,QUO) ! Return all $00$ back to quotes
X1$=SUB(X1$, ",@()", "") ! Remove Dummy position


This will double up the quotes within the string.  Of course this assumes the format of the string is consistent.


Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com

Lawrence_Leavell

  • Silver Member
  • ***
  • Posts: 49
    • View Profile
Re: detect embedded quotes
« Reply #6 on: January 31, 2019, 01:08:31 PM »
Mike,
With minor mods, your suggestion worked. Thanks a lot!