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.
![](https://eu-images.contentstack.com/v3/assets/blt740a130ae3c5d529/bltba62518415cda0e2/652fe6ddbc479f8697ef691f/default-cubic.png?width=1280&auto=webp&quality=95&format=jpg&disable=upscale)
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;
}
Read more about:
BlogsAbout the Author(s)
You May Also Like