stringbuilder
This is an old revision of the document!
The StringBuilder
If you are processing strings, of course you can concatenate them using the + operator:
cString := "Hello" + " " + "from" + " " + "my" + " " + "X#" + " " + "program"
But if you are building longer strings, composed by many substrings, you should use the System.Text.StringBuilder class. Is is much more efficient when dealing with many string parts:
using System.Text
oSB := StringBuilder{}
oSB:Append( "Hello" )
oSB:Append( " " )
oSB:Append( "from" )
oSB:Append( " " )
oSB:Append( "my" )
oSB:Append( " " )
oSB:Append( "X#" )
oSB:Append( " " )
oSB:Append( "program" )
System.Console.WriteLine( oSB:ToString() )
The StringBuilder class has also a AppendFormat method, and many other interesting methods to work with the string, like Replace, Copy and Insert. Please see MSDN for more details - specially the docs page has a very long and detailled description of this class, together with useful samples.
stringbuilder.1517086589.txt.gz · Last modified: 2018/01/27 20:56 by wolfgangriedmann