Click to See Complete Forum and Search --> : Saving the contents of a Textarea to a file...


Mike Burdick
06-01-2007, 08:46 PM
Hi,

I'm saving the contents of a textarea to a file. The problem I'm having is that when a carriage return is entered in the textarea the file being saved also reads this and saves the remaining data after that as a new line - which screws up everything! Is there a way I can get the carriage return to be skipped over when saving the file; but still be retained for reading back into the textarea?

Thanks...

Nedals
06-01-2007, 09:15 PM
Basically No!
When you save a '\n' to a file, it will create a new line.

The solution is to convert the '\n' to a character that will not appear in your text, say a '^', then save the string to the file. Simply reverse the process when reading back.

Beware however, that the textarea is likely to return '\r\n' not just '\n' so be careful with your conversion. Returning '\n' to the textarea will work ok.

Mike Burdick
06-01-2007, 09:41 PM
Nadals,

Thanks!

I was thinking I could just escape the value and save it but I guess that won't work..

I'll give your suggestion a try - there is no reason that shouldn't work!