C
Chris Dunaway
I am using a StringBuilder like this:
Dim sb As New StringBuilder
sb.Append("Text field 1: {TXT1}" & VbCrLf)
sb.Append("Text field 2: {TXT2}" & VbCrLf)
sb.Append("Text field 3: {TXT3}" & VbCrLf)
And then later in the code I use this:
Dim sText1Value As String
Dim sText2Value As String
Dim sText3Value As String
sb.Replace("{TXT1}", sText1Value)
sb.Replace("{TXT2}", sText2Value)
sb.Replace("{TXT3}", sText3Value)
My question concerns the length of the string values in the sText1Value
variables. What if their lengths are greater than the tokens ({TXT1},
{TXT2}) that I inserted into the StringBuilder at the beginning?
Will that cause an unnecessary string allocation? Should I make the
tokens as long as the maximum string length that I think will be
replaced? e. g. :
sb.Append("Text field 1: {TXT1LONGTOKENLENGTH}" & VbCrLf)
Would the StringBuilder still have to make an extra string allocation
in this case or would it just be able to replace the characters in
place? Should I even be concerned about it?
I could not examine the Replace function with ILDASM or Reflector to
see exactly what it did.
Thanks
Dim sb As New StringBuilder
sb.Append("Text field 1: {TXT1}" & VbCrLf)
sb.Append("Text field 2: {TXT2}" & VbCrLf)
sb.Append("Text field 3: {TXT3}" & VbCrLf)
And then later in the code I use this:
Dim sText1Value As String
Dim sText2Value As String
Dim sText3Value As String
sb.Replace("{TXT1}", sText1Value)
sb.Replace("{TXT2}", sText2Value)
sb.Replace("{TXT3}", sText3Value)
My question concerns the length of the string values in the sText1Value
variables. What if their lengths are greater than the tokens ({TXT1},
{TXT2}) that I inserted into the StringBuilder at the beginning?
Will that cause an unnecessary string allocation? Should I make the
tokens as long as the maximum string length that I think will be
replaced? e. g. :
sb.Append("Text field 1: {TXT1LONGTOKENLENGTH}" & VbCrLf)
Would the StringBuilder still have to make an extra string allocation
in this case or would it just be able to replace the characters in
place? Should I even be concerned about it?
I could not examine the Replace function with ILDASM or Reflector to
see exactly what it did.
Thanks