April 13, 201015 yr 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
April 13, 201015 yr 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")
April 13, 201015 yr 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
April 15, 201015 yr 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;" )
April 17, 201015 yr 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