05-12-2011 12:59 PM
I have simple txt file called file1.txt which contains:
I have this code which reads the file and puts the contents into variable called str:
var file:File = File.applicationDirectory; file = file.resolvePath("file1.txt"); var fileStream:FileStream = new FileStream(); fileStream.open(file, FileMode.READ); var str:String = fileStream.readMultiByte(file.size, File.systemCharset); str = str.replace(/\n/g, File.lineEnding); fileStream.close(); trace(str);
When I run this code I get this:
(there is an extra blank line at the end of each line!)
I searched all over and I understand text file created in Windows ads an extra line start after line end which Flash interprets as extra line hence I added recommended (below) to convert it to devices line end.... Any ideas how to overcome this?
str = str.replace(/\n/g, File.lineEnding);
Solved! Go to Solution.
05-12-2011 01:08 PM
Maybe it works when you replace the regexp with a string that contains "\n".