StringBuilder in Flex

☆樱花仙子☆ 提交于 2019-11-30 16:48:19

问题


I'm looking for fast string concatenation class or so in Flex. Like StringBuilder in Java.

Thanks


回答1:


var str1:String = "Vinoth";
var str2:String = "Babu";
var str3:String = "Chennai";
var str4:String = concat(str1, " ", str2, " ", str3)

trace(str4) would result you str4 == "Vinoth babu Chennai"

String Concat Class

public class StringBuffer
{
    public var buffer:Array = new Array();

    public function add(str:String):void
    {
        for (var i:Number = 0; i < str.length; i++)
        {
            buffer.push(str.charCodeAt(i));
        }
    }

    public function toString():String
    {
        return String.fromCharCode.apply(this, buffer);
    }
}

Here you have a more indepth than the above class written.

http://blogs.adobe.com/pfarland/2007/10/avoiding_string_concatenation.html




回答2:


You can create an array of strings and then use String.concat to combine them.

However, I've never seen string manipulation come up as a bottleneck when profiling a Flex app. I have in .NET, but not Flex.



来源:https://stackoverflow.com/questions/2815503/stringbuilder-in-flex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!