views:

71

answers:

2

Hi guys,

I am creating a AIR application in flex. I have a textArea having a string something like -

AAA BBB CCC DDD
QQQ WWW EEE SSS
KKPPP SSSL AAAS

I want this to save this into .txt file.

I am using -

file.save(output.text,"testFile.txt");

But its is saving everything in 1 line. When I open the file using notepad everything is coming as Single line.

Does flex provide any functionality using which I can save the contents of multiline Text Area into .txt file?

The output string has got the '\n' but notepad is not able to recognize it. Is it a Flex issue or Windows notepad issue? If it is notepad issue then is there any way to work around this from Flex file io?

Please help. :)

+2  A: 

Notepad is the culprit - it only understands \r\n newlines (the Windows newlines).

Open the file in wordpad or notepad++ and you can see the text in multiple lines.

If you want to support notepad too, you can replace \n with \r\n before writing it to the file - smart editors will convert them to single \n before displaying it:

file.save(output.text.replace("\n", "\r\n"), "testFile.txt");
Amarghosh
This worked. Thanks a ton :)
psvm
+1  A: 

Don't get into that jungle, you are not going to get it right. Take a look to File.lineEnding and let Adobe deal with it.

Cheers,

J

Zárate
This is also very useful. Thanks alot :)
psvm