PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Commas and Quotes embedded in data for PRINT to csv file  (Read 926 times)

steven.rajski

  • Member
  • **
  • Posts: 12
    • View Profile
Commas and Quotes embedded in data for PRINT to csv file
« on: July 09, 2021, 04:57:31 PM »
I have data that needs to be in its own column.  Some fields have a leading double quote (") and some have embedded commas.  Here's my print statement:

3100 LET QO$=$22$,SQO$=$22$+$2C$+$3D$+$22$
QO$   is "
SQO$ is ",="


3513 IF MID(SMCROSS$,1,1)=$22$ THEN PRINT (ONEPRICEDUMP)QO$,SMPRC$,"="+CQO$,SMC
3513:ROSS$,SQO$,DUPRESIND$,SQO$, ELSE PRINT (ONEPRICEDUMP)QO$,SMPRC$,SQO$,SMCRO
3513:SS$,SQO$,DUPRESIND$,SQO$,

My goal is to at least show the data with a leading double quote as it is.





Ken Sproul

  • Gold Member
  • ****
  • Posts: 60
    • View Profile
Re: Commas and Quotes embedded in data for PRINT to csv file
« Reply #1 on: July 09, 2021, 05:46:35 PM »

I find it helpful to create a function that handles the quoting.

For example:
Code: [Select]
def fn_str$(local x$)
local a_number,x=num(x$,err=*next); a_number=1
return tbl(a_number or pos($2C22$:x$),x$,"="+$22$+sub(x$,$22$,$2222$)+$22$)
end def


print (channel)fn_str$(string1$),",",str(number1),",",fn_str$(string2$),",",fn_str$(string3$),",",str(number2)

Ken Sproul
DPI Information Service, Inc.
Pivotal Systems LLC

Mike King

  • Diamond Member
  • *****
  • Posts: 3811
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: Commas and Quotes embedded in data for PRINT to csv file
« Reply #2 on: July 12, 2021, 09:44:13 AM »
Have you looked at using the :[STR(",")] format?

For example:

  a$=QUO+"CAB-MSTR..."
  b$="N"
  c=344.40
  PRINT IOL=theiol
!
theiol:IOLIST a$:[STR(",")],b$:[STR(",")],c:[STR(",")]

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

steven.rajski

  • Member
  • **
  • Posts: 12
    • View Profile
Re: Commas and Quotes embedded in data for PRINT to csv file
« Reply #3 on: July 16, 2021, 05:52:03 PM »
Thank you for your help.  Your suggestion work beautifully.