Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

What character encoding to get CR/LF

Featured Replies

Hi All,

I am using the WriteToFile function in ScriptMaster v3.33 with FM 10 Adv on Windows. I want to create a plain ASCII text file with CR/LF as the end of line characters.

First I put my text field into a local variable $text and replace all CR with CR/LF using:

Substitute( $text; [Char( 11); ""]; [ Char( 13); Char( 13) & Char (10)] )

Then I use WriteToFile to create the file.

I have tried several character encodings when I register the WriteToFile function (ASCII, utf-8) but they replace my CR/LF with LF. I tried to specify MS-DOS but that encoding is not supported.

Does anyone know what character encoding I can use? Or a simple trick to preserve the CR/LF?

Thanks -- Mark

Mark, ScriptMaster converts the line breaks on text passed in as parameters. This includes both variables and the actual function bodies.

To get a CR in your output, I think your best option is to do the substitution in java, referencing the CR as its numeric value.

Try something like this in your script, which replaces all newlines with a newline and carriage return.

text.replace("n","rn")

  • Author

Hi Sam,

I'm not sure how to include that piece of code. I tried this and it failed when I called WriteToFile:

RegisterGroovy( "WriteToFile( filePath ; textToWrite )" ; "//This simple version uses utf-8¶

//new File( filePath ).write( textToWrite );¶

//This more advanced version allows you to specify the character encoding¶

OutputStreamWriter writer = new OutputStreamWriter( new FileOutputStream( filePath ), "utf-8" );¶

text.replace("n","rn");¶

writer.write( textToWrite );¶

writer.close();¶

return true;" )

Did you mean for me to alter the groovyscript? If so, where does it go? Thanks -- Mark

Try this:

RegisterGroovy( "WriteToFileWithCarriageReturns( filePath ; textToWrite )" ; "//This simple version uses utf-8¶

//new File( filePath ).write( textToWrite );¶

¶

//This more advanced version allows you to specify the character encoding¶

OutputStreamWriter writer = new OutputStreamWriter( new FileOutputStream( filePath ), "utf-8" );¶

writer.write( textToWrite.replace("n", "rn") );¶

writer.close();¶

return true;" )

  • Author

Hi Sam,

That is just what I needed to know. Thanks for your product and your help -- Mark

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.