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, Los Angeles, CA, USA
9.12.23
Senior Level Designer (Zombies)

PlayStation Studios Creative Arts

Petaling Jaya, Selangor, Malaysia
9.14.23
Lead Concept Artist

High Moon Studios

Carlsbad, CA, USA
9.20.23
Technical Designer at High Moon Studios

High Moon Studios

Carlsbad, CA, USA
9.18.23
VFX Artist
More Jobs   

CONNECT WITH US

Explore the
Advertise with
Follow us

Game Developer Job Board

Game Developer

@gamedevdotcom

Explore the

Game Developer Job Board

Browse open positions across the game industry or recruit new talent for your studio

Browse
Advertise with

Game Developer

Engage game professionals and drive sales using an array of Game Developer media solutions to meet your objectives.

Learn More
Follow us

@gamedevdotcom

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