We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

loadVars(  ) and line breaks, trouble

Donelson
Donelson asked
on
Medium Priority
257 Views
Last Modified: 2009-07-29
I thought I had compensated for all the weird ways to do line breaks for Macs and PCs...  But apparently NOT !

The code below works fine in the Flash 8 Pro IDE, also works fine when run in Safari, Firefox and IE on a Mac (as LOCAL FILES), but does NOT work when uploaded and run in Safari, Firefox or IE from the internet....

The code below reports that only ONE line has been read into the array
from the file at ---
   http://www.armchair-travel.com/vt/105_Hospitality/descr.txt

 I know there are 53 lines in the file....

What am I doing wrong, please ?

===============================


var loadFile = new LoadVars();
loadFile.onData = function(theDescr:String) {  // called when data file is Completely Loaded
      var theLines:Array;
      // Split either Mac or PC formatted descr.txt files into separate lines
      theDescr = String(theDescr).split("\r\n").join("\r");
      //
      theDescr = theDescr.split("\t").join("");    // remove tabs
      theLines = String(theDescr).split("\r");  // break into lines
      //
      statusField.text = "descr.txt: " + theLines.length + " lines loaded."
.....
...
..

}


Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2008

Commented:
Issue is in the following line
----------
 theLines = String(theDescr).split("\r");  // break into lines
--------------

you should use "\n" here..
-----------
 theLines = String(theDescr).split("\n");  // break into lines
----------

Rgds
Aneesh
CERTIFIED EXPERT
Top Expert 2008

Commented:
Problem is :

following line of code not working actually.
(you can remove this line of code... it is doing nothing.)
----------
 theDescr = String(theDescr).split("\r\n").join("\r");
----------

flash does not get "\r\n" to split... that so it has nothing to join using "\r"...


Author

Commented:
When I use your suggestions, then the program does not work on local machines.
CERTIFIED EXPERT
Top Expert 2008

Commented:
Use the following code it will work for both
----------
var loadFile = new LoadVars();
loadFile.onData = function(theDescr:String) {  // called when data file is Completely Loaded
     var theLines:Array;
     // Split either Mac or PC formatted descr.txt files into separate lines
     theDescr = String(theDescr).split("\r\n").join("\n");
     //
     theDescr = theDescr.split("\t").join("");    // remove tabs
     theLines = String(theDescr).split("\n");  // break into lines
     //
     statusField.text = "descr.txt: " + theLines.length + " lines loaded."
.....
...
..

}
-------------

here if text has "\r\n" replace it with "\n" and later we are spliting the lines with" \n"

Rgds
Aneesh

Author

Commented:
When I load the file Locally on the Mac, the line break is charCode 0x0d (13).

When I load the file via the internet (on the Mac), the line break char code is 0x0a (10).

What kind of BULLSHT is that !???  

What kind of brain damage switches chars around in a file differently between Local Access and Internet Access ?

Author

Commented:

-- "here if text has "\r\n" replace it with "\n" and later we are spliting the lines with" \n"

Does not work on Mac. Mac uses only 0x0d.
CERTIFIED EXPERT
Top Expert 2008

Commented:
It may depend on server, how server parse a normal text file..
anyway just look for solution to your problem,

My above suggestion will work fine for both...

Rgds
Aneesh
CERTIFIED EXPERT
Top Expert 2008
Commented:
ok then here the solution
----------
var loadFile = new LoadVars();
loadFile.onData = function(theDescr:String) {  // called when data file is Completely Loaded
     var theLines:Array;
     // Split either Mac or PC formatted descr.txt files into separate lines
     theDescr = String(theDescr).split("\r\n").join("\r");
     theDescr = String(theDescr).split("\n").join("\r");
     //
     theDescr = theDescr.split("\t").join("");    // remove tabs
     theLines = String(theDescr).split("\r");  // break into lines
     //
     statusField.text = "descr.txt: " + theLines.length + " lines loaded."
.....
...
..

}
--------------

replace "\r\n" with "\r",
then replace existing "\n" with also "\r"

and split the lines now using "\r"

Rgds
Aneesh

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
This works now ---
==============


            // Split either Mac or PC formatted descr.txt files into separate lines
            theDescr = theDescr.split("\r\n").join("\n");
            theDescr = theDescr.split("\r").join("\n");
            //
            theDescr = theDescr.split("\t").join("");    // remove tabs
            theLines = theDescr.split("\n");  // break into lines
            //
==============

What a load of horse droppings !!!

Thanks, for your help, Aneesh.

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.