Jump to content
Sign in to follow this  

CRFL write to file

Recommended Posts

Hi all,

I have the same problem as a previous post in 2010 (archived since).

"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


It was proposed to register a new groovy function which seemed to work.

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


return true;" )

But I have FM12 and Windows 7 - it doesn't accept this function because of

"utf-8" and if I write \"utf-8\" it then says that there is a problem with ("n", "rn")

Can anybody help me please? Thanks


Share this post

Link to post
Share on other sites

You dont need to do that subtitute in FM

In ScriptMaster it should be

textToWrite.replace('n' , 'rn')

You are not replacing n with rn as in orange >> ornange

The "" character is required to escape the new line and carriage return characters.

You could also try 'iso-8859-1' as the encoding

In Groovy (in most cases) you can use ' instead of " as it then means it is easier when it gets into FM to debug as there are not lots of " sitting in the middle of the function

Share this post

Link to post
Share on other sites

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

Sign in to follow this  


Important Information

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