29. July 2008 00:01
/
jstawski
/
Comments (1)
I was in need of using some brackets with the AppendFormat of the StringBuilder class, but the brackets are a special character for the AppendFormat. The function uses the brackets to indicate variable placement. So in the code below the {0} will be replaced with the value of the variable name.
StringBuilder sb = new StringBuilder();
sb.AppendFormat("Hello, my name is {0}", name);
Dim SB As New StringBuilder()
SB.AppendFormat("Hello, my name is {0}", Name)
If you want to add a bracket to the StringBuilder and you also want to use the AppendFormat then you need to escape it by doing double brackets {{ or }}.
sb.AppendFormat("Hello, my name is {0} and these are brackets: {{ }}", name);
SB.AppendFormat("Hello, my name is {0} and these are brackets: {{ }}", Name)
Happy Programming!
330314ea-88ec-475f-b65b-ce4939e5c24a|0|.0|27604f05-86ad-47ef-9e05-950bb762570c