AS3 has never had very good support for multi-line strings… until now. Today’s article discusses the proper and improper ways of writing multi-line strings and delves into the bytecode so you really understand what’s going on.
Posts Tagged concatenate
When a recent comment asked about string concatenation performance, I realized that there are a lot of ways to build strings in AS3 and I hadn’t tested any of them. Leaving aside the sillier ones like the XML class or joining Array
objects, we have two serious contenders: the lowly +
operator (i.e. str + str
) and the ByteArray
class. Which will triumph as the ultimate way to build strings quickly?
It struck me recently that there are a lot of ways to convert variables of many types to a the String type. The ease of doing this is one of AS3’s strengths over languages where it’s error-prone, possibly insecure, and just plain difficult. The C language is the most obvious example of this and, since then, seemingly every language has enshrined string conversion in ways ranging from global String() functions (AS3) that take any variable to adding toString() to the base Object type (Java, AS3, others). AS3 seems to have chosen “all of the above” and there are now many ways to convert to a string. Below I’ll look at them from a performance standpoint and see if the everyday, run-of-the-mill boring string conversion can be improved by choosing one option over another.