problems with new line character in a text file on Windows

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
dcrooks
Posts: 9
Joined: December 14th, 2010, 9:13 pm

hi people

I'm having an issue with a script that generates a .txt file. The script is being run on a mac and the end of line characters are fine when read on a mac but aren't being interpreted correctly on the PC (Notepad displays one very long line separated with the square box unrecognised character symbols). I've done quite a bit of searching, including these forums, and found numerous mentions of the different newline characters used by mac,unix,windows and the problems thereof but no clear solutions. any advice greatly appreciated.

below is a test script with the various linefeed options. (i've also tried a couple of different .encoding and .lineFeed options without luck)

cheers../daniel

Code: Select all

{
   var theFile = new File (Folder.myDocuments.absoluteURI + "/test.txt");
   theFile = theFile.saveDlg("Save test file.");
   
   if (theFile != null) {  
      lorem = "data string";
      theFile.open("w","TEXT","????");
      theFile.write("///various linefeed options ///\r");  
      theFile.write("using \\r, " + lorem + "\r");
      theFile.write("using \\n, " + lorem + "\n");
      theFile.write("using \\r\\n, " + lorem + "\r\n");
      theFile.write("using \\n\\r, " + lorem + "\n\r");
      theFile.write("using \\f, "+ lorem + "\f");
      theFile.write("using \\u000A, " + lorem + "\u000A");
      theFile.write("using \\u000D, " + lorem + "\u000D");
      theFile.writeln("using writeln, " + lorem);
      theFile.writeln("using writeln, " + lorem);
      theFile.writeln("using writeln, " + lorem);      
      theFile.close();
   }
}
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

If I run this on a Mac and open the result in Win Notepad, I don't get any strange characters:

{
var myOutputFolder = Folder.selectDialog("Please navigate to output folder.");
var myFilePath = myOutputFolder.path + "/" + myOutputFolder.name + "/" + "test.txt";
var myFile = new File (myFilePath);
myFile.open("w");
myFile.lineFeed = "windows";
myFile.writeln("Line 1");
myFile.writeln("Line 2");
myFile.writeln("Line 3");
myFile.writeln("Line 4");
myFile.close();
}


Dan
dcrooks
Posts: 9
Joined: December 14th, 2010, 9:13 pm

Dan

you are a legend !
lineFeed = "windows" !!!!
that was one of the first things I randomly tried but for whatever reason it didn't work, I must have messed something else up.
thank you so much, I really had almost given up.

../daniel
Post Reply