.. _dojox/string/Builder: dojox.string.Builder ===================== :Status: Draft :Version: Dojo Toolkit 1.0+ :Author: Tom Trenka The DojoX String Builder is a constructor designed to make working with large strings, particularly in the context of recursive functions, much more efficient and performant. The basic idea (borrowed primarily from the .NET Framework and heavily optimized) is that you can pass around a single Builder object (since objects are passed by reference and not by value) to various functions, and have each function *append* string fragments to the Builder; when you are finished, you can simply add the Builder to an existing string or explicitly call the toString method. A simple example of using the Builder: .. code-block :: javascript :linenos: dojo.require("dojox.string.Builder"); var sb = new dojox.string.Builder(); function addOne(builder){ var s = getSomeString(); // imagine this is a function that returns a decent sized string builder.append(s); return builder; } function addTwo(builder, str){ builder.append(str); return builder; } addOne(sb); addTwo(sb, "The rain in spain falls mainly on the plain"); var output = "This is a builder test " + sb; While the above example is pretty basic, it demonstrates the usage pretty well. Situations where using a string builder is handy are template systems and serialization systems; for instance, creating a simple table could be written so that it uses the Builder as opposed to recursively calling itself and returning/appending string fragments. Here's an example: .. code-block :: javascript :linenos: dojo.require("dojox.string.Builder"); function buildRow(builder){ builder.append("