Skip navigation
Currently Being Moderated

Exporting string to csv keeping commas and new lines

May 3, 2012 12:46 AM

Hi there,


I am exporting string to csv and have been removeing new lines and commas like so


thing.toString().replace(/\n/g, '').replace(',','') ;


how can I do this iwthout losing the line breaks and commas? I can't have them in atm because messes up the csv.

  • Currently Being Moderated
    May 3, 2012 5:02 AM   in reply to nikos101

    If you wanrt to keep them, don't remove them.

    Mark as:
  • Currently Being Moderated
    May 3, 2012 6:02 AM   in reply to nikos101

    Ditch CSV and try a more robust format like JSON:


    We're talking strings, numbers, arrays and objects serialized and deserialized. Just scroll down for a giant list of encoders and decoders in any language of your choice, of course including ActionScript. JSON is used heavily in AJAX JavaScript (which is ECMAScript compliant, just like ActionScript).


    Otherwise for superior situations, use the binary AMF protocol.

    Mark as:
  • Currently Being Moderated
    May 3, 2012 6:17 AM   in reply to nikos101

    JSON is for 'transfering' information that can be reassembled into number, string, array, object, etc. format afterwards.


    Excel can import CSV but it might not understand the complexity of the information. Tyically what you would do is serialize complex information with JSON, recieve it on the other side (wherever that might be) and then deserialize it. After you deserialize it using JSONs abilities to turn your information back into what is was (numbers, strings, arrays and object) it is up to you how you restructure the data for the format you choose.


    Your original intent of preserving CSV is best for Excel or OpenOffice Calc. You didn't mention your intent. JSON would package those (CRLF) \n's for you.

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points