Skip to main content
Known Participant
November 29, 2009
Answered

Imported text strings have new lines where they shouldn't

  • November 29, 2009
  • 1 reply
  • 828 views

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.

This topic has been closed for replies.
Correct answer kglad

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.

1 reply

kglad
Community Expert
November 29, 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.

ziggy067Author
Known Participant
November 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

kglad
kgladCorrect answer
Community Expert
November 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.