informa
1 min read
Blogs

AS3 Read a line of text from txt file.

I've ran into some problems when reading strings from text files so I wrote a simple function to do it for me. Hopefully others will either find this useful or have a better way of doing it.

I've ran into some problems when reading strings from text files so I wrote a simple function to do it for me. Hopefully others will either find this useful or have a better way of doing it.

 

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

public static function ReadLine(data:ByteArray):String
{
    var eol:Boolean = false; //eol = end of line
    var str:String = "";

    while (data.bytesAvailable > 0 && !eol)
    {
        var char:String = data.readUTFBytes(1);
        if (char.charCodeAt(0) == '\n'.charCodeAt(0))
        {
            //Assert.AssertIf(false, str);
            eol = true;
        }
        else if (char.charCodeAt(0) == '\r'.charCodeAt(0))
        {
        }
        else
            str += char;
    }
   
    return str;
}

Latest Jobs

Treyarch

Playa Vista, California
6.20.22
Audio Engineer

Digital Extremes

London, Ontario, Canada
6.20.22
Communications Director

High Moon Studios

Carlsbad, California
6.20.22
Senior Producer

Build a Rocket Boy Games

Edinburgh, Scotland
6.20.22
Lead UI Programmer
More Jobs   

CONNECT WITH US

Register for a
Subscribe to
Follow us

Game Developer Account

Game Developer Newsletter

@gamedevdotcom

Register for a

Game Developer Account

Gain full access to resources (events, white paper, webinars, reports, etc)
Single sign-on to all Informa products

Register
Subscribe to

Game Developer Newsletter

Get daily Game Developer top stories every morning straight into your inbox

Subscribe
Follow us

@gamedevdotcom

Follow us @gamedevdotcom to stay up-to-date with the latest news & insider information about events & more