Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
0

Imported text strings have new lines where they shouldn't

New Here ,
Nov 28, 2009 Nov 28, 2009

Using AS3 in flash CS4

Hi i have some imported text from a tab delimited/seperated text file (.txt).

I have split the values into an array using  .split('\n') .split('\t')

I have stored the imported data into an array where each column has a new index and the properties of each row can be gained from array.property. For example array[4].name would give the 'name' of the 4th entity in the original text file.

This all works fine however some of the separated strings are formatted incorrectly as they take up 2 lines instead of one.

The first string in each line in the original text file is imported into flash with a new line above it. I.e: "Property1" in the original tab delimited/seperated text file is stored in flash as "

Property1" with a new line above it. I need to get rid of this new line in order to appropriately display the text in text fields.

Can someone please help.

P.S: I do not want to change my importing file format from a tab delimited text file to something like xml so please don't suggest it.

TOPICS
ActionScript
809
Translate
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

Community Expert , Nov 29, 2009 Nov 29, 2009

those are not string-strip functions.  those are whitespace characters.  all whitespace characters are escaped by the backslash character.

i used two of them and in my years of using flash i've never used more than those two and \t = tab, though i know of two more:

\b = backspace

\f = formfeed

i used:

\r = carriage return

\n = new line

the code i gave converted a newline, followed by a carriage return to a new line, only.  and it converted a carriage return followed by a new line to a new line, only.

p

...
Translate
Community Expert ,
Nov 28, 2009 Nov 28, 2009

some text editors add a new line and a carriage return.  to remedy, use:

s=s.split("\r\n").join("\n").split("\n\r").join("\n");

before you apply the rest of your string methods.

Translate
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
New Here ,
Nov 29, 2009 Nov 29, 2009

Thanks that worked.

How does it work? - I don't know what .split('\r') does.

I'm guessing 'r' stands for Return but how is this different to new line - .split('\n')

Where can i find a list of what all string slip functions (.split('\n'),.split('\r'),.split('\t') ect...)

Thanks

Translate
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
Community Expert ,
Nov 29, 2009 Nov 29, 2009

those are not string-strip functions.  those are whitespace characters.  all whitespace characters are escaped by the backslash character.

i used two of them and in my years of using flash i've never used more than those two and \t = tab, though i know of two more:

\b = backspace

\f = formfeed

i used:

\r = carriage return

\n = new line

the code i gave converted a newline, followed by a carriage return to a new line, only.  and it converted a carriage return followed by a new line to a new line, only.

please mark this thread as answered, if you are still able.

Translate
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
New Here ,
Nov 29, 2009 Nov 29, 2009

thanks very much

Translate
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
Community Expert ,
Nov 29, 2009 Nov 29, 2009
LATEST

you're welcome.

Translate
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