Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 5345 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

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

Posted

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")

Posted

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

Posted

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;" )

This topic is 5345 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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