• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Exporting string to csv keeping commas and new lines

Enthusiast ,
May 03, 2012 May 03, 2012

Copy link to clipboard

Copied

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.

TOPICS
ActionScript

Views

969

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 03, 2012 May 03, 2012

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

...

Votes

Translate

Translate
LEGEND ,
May 03, 2012 May 03, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 03, 2012 May 03, 2012

Copy link to clipboard

Copied

but they mess up the csv, data in the wrong columns

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 03, 2012 May 03, 2012

Copy link to clipboard

Copied

Ditch CSV and try a more robust format like JSON:

http://www.json.org/

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 03, 2012 May 03, 2012

Copy link to clipboard

Copied

but the users download the csv and open in excel, can it be done in JSON?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 03, 2012 May 03, 2012

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines