Subscribe Bookmark RSS Feed

adding double quotes and saving as .txt file

mpg

Community Trekker

Joined:

Oct 5, 2014

Hello JMP community,

the following script produces a 1x2 data table with character type cell values.  The values in the cell are enclosed with double quotes (thanks to PMroz and MS for earlier posts on this) and then I save the table as a .txt file.

When I open the .txt file with a reader the double quotes are enclosed by additional double quotes:

sourcedId,status

"""000""","""active"""

Is there a way to save the table so that the final result looks like:

sourcedId,status

"000","active"

Orgs = New Table( "Orgs",

Add Rows( 1 ),

New Column( "sourcedId",

Character,

Nominal,

Set Values( { "\["000"]\" } )

),

New Column( "status",

Character,

Nominal,

Set Values( {"\["active"]\"} )

);

Orgs << Save As( "C:\Pathway\Orgs11.txt" );

Close(Orgs, noSave);

Many thanks in advance!

Sincerely,

MPG

3 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

Here is a solution, that might meet your requirements.  While it does not just use a Save As() function, but instead uses a Save Text File().  This takes a little more coding, but it does create the file structure you want

Names Default To Here( 1 );

Orgs = New Table( "Orgs",

       Add Rows( 1 ),

       New Column( "sourcedId", Character, Nominal, Set Values( {"\["000"]\"} ) ),

       New Column( "status", Character, Nominal, Set Values( {"\["active"]\"} ) )

);

//Orgs << Save As( "C:\users\txjim\Orgs11.txt" );

Save Text File( "C:\users\txjim\Orgs11.txt", "sourcedId,status\!n" );

For( i = 1, i <= N Rows( Orgs ), i++,

       Save Text File(

              "C:\users\txjim\Orgs11.txt",

              orgs:sourcedId || "," || orgs:status || "\!n",

              Mode( "append" )

       )

);

Close( Orgs, noSave );

Jim
mpg

Community Trekker

Joined:

Oct 5, 2014

Thanks, that works well.  The files I am working with are quite large, though the looping doesn't seem to be causing any major slowdowns.

Sincerely,

Matt

Craige_Hales

Staff

Joined:

Mar 21, 2013

Does JSL have a file stream? if the file size does become an issue...you can build the text in memory and write the file in one operation.

Craige