cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
FN
FN
Level VI

JSL Saving txt files with Windows end of line ( EOL CRLF )

I have a string which I want to save with end of line compatible with Windows (CRLF EOL).

How or when can I specified such thing?

 

 

names default to here(1);
clear log();

my_string = "\[Hello
""
World!]\";

show(my_string);

Write(my_string);

// prints in JMP Log
// "Hello
// ""
// World!"

saveTextFile("$desktop/my_text.txt", my_string );

// See output in Notebook++ below

FN_0-1607252573736.png

 

This is the desired output I am after:

FN_1-1607264959849.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Super User

Re: JSL Saving txt files with Windows end of line ( EOL CRLF )

Sometimes JMP is too helpful with the CR LF normalization for the OS it is running on. If you know exactly the byte sequence you want, make a blob and use SaveTextFile to save the blob. Something like (untested, but close...)

txt = "my\!ntext\!r.";
filename = SaveTextFile("$temp/x.bat", charToBlob( txt ) );

second edit:  you can test like this

txt = "my\!ntext\!r.";
filename = SaveTextFile("$temp/x.bat", charToBlob( txt ) );
write(loadtextfile(filename,BLOB));

Char To Blob( "my~0Atext~0D.", "ascii~hex" )

which shows the binary data found in the re-loaded file. ~0A is the hex code for the line feed and 0D for the carriage return.

 

third edit: use \!N (capital N) if your JSL is running on windows. It will make the CRLF on Win, something else if running on Mac. Do NOT press return in the middle of a quoted string in the JMP editor window; that will only make a CR (on windows JMP, can't tell you about Mac JMP, except it will be different.)

For portable results (JSL running on Win and Mac), use \!r\!n (lower case r and n) AND the charToBlob() function with saveTextFile.

 

Craige

View solution in original post

6 REPLIES 6
txnelson
Super User

Re: JSL Saving txt files with Windows end of line ( EOL CRLF )

This is handled with Escape Sequences.  Documented in the Scripting Guide, available in the JMP Documentation Library under the Help pull down menu.

crlf.PNG

Jim
Jeff_Perkinson
Community Manager Community Manager

Re: JSL Saving txt files with Windows end of line ( EOL CRLF )

@txnelson has the right answer.

 

Try this:

 

my_string = "Hello\!N\!"\!"\!NWorld!\!N";
-Jeff
Georg
Level VII

Re: JSL Saving txt files with Windows end of line ( EOL CRLF )

I think the text has been saved correctly with Windows end of line (at least at my System win 10 JMP 15).

I opened the file in Notepad and saw no issue,

but if I check (view-> Show Symbol -> not printable characters -> Show Symbols -> Show end of line) I see the same as you, see screenshot.

Please check your Settings in Notepad, or use different Program ..

notepad_CR.PNG

 

 

Georg
FN
FN
Level VI

Re: JSL Saving txt files with Windows end of line ( EOL CRLF )

I am after this, otherwise a bat file will not be executed just printed out.

FN_0-1607265005629.png

 

Georg
Level VII

Re: JSL Saving txt files with Windows end of line ( EOL CRLF )

Sorry, haven't understood fully your initial question, you're right.

Georg
Craige_Hales
Super User

Re: JSL Saving txt files with Windows end of line ( EOL CRLF )

Sometimes JMP is too helpful with the CR LF normalization for the OS it is running on. If you know exactly the byte sequence you want, make a blob and use SaveTextFile to save the blob. Something like (untested, but close...)

txt = "my\!ntext\!r.";
filename = SaveTextFile("$temp/x.bat", charToBlob( txt ) );

second edit:  you can test like this

txt = "my\!ntext\!r.";
filename = SaveTextFile("$temp/x.bat", charToBlob( txt ) );
write(loadtextfile(filename,BLOB));

Char To Blob( "my~0Atext~0D.", "ascii~hex" )

which shows the binary data found in the re-loaded file. ~0A is the hex code for the line feed and 0D for the carriage return.

 

third edit: use \!N (capital N) if your JSL is running on windows. It will make the CRLF on Win, something else if running on Mac. Do NOT press return in the middle of a quoted string in the JMP editor window; that will only make a CR (on windows JMP, can't tell you about Mac JMP, except it will be different.)

For portable results (JSL running on Win and Mac), use \!r\!n (lower case r and n) AND the charToBlob() function with saveTextFile.

 

Craige