public void AppendLineFormat() { StringBuilder Builder = new StringBuilder(); Builder.AppendLineFormat("This is test {0}", 1); Assert.Equal("This is test 1" + System.Environment.NewLine, Builder.ToString()); Builder.Clear(); Builder.AppendLineFormat("Test {0}", 2) .AppendLineFormat("And {0}", 3); Assert.Equal("Test 2" + System.Environment.NewLine + "And 3" + System.Environment.NewLine, Builder.ToString()); }
public void StringBuilder_AppendLineFormat() { var A = "A"; var B = "B"; var C = "C"; var format = "{0}{1}{2}"; var delimiter = ";;"; var expected = "ABC;;CBA;;BCA"; var sb = new StringBuilder(); sb.AppendLineFormat(format, new object[] { A, B, C }, delimiter); sb.AppendLineFormat(format, new object[] { C, B, A }, delimiter); sb.AppendLineFormat(format, new object[] { B, C, A }, delimiter); Assert.AreEqual(expected, sb.ToString()); }
public static string ToJson(Dictionary<string, string> variables) { var builder = new StringBuilder(); builder.AppendLine("{"); var last = variables.Last().Key; foreach (var variable in variables) { var isLast = (variable.Key == last); int value; if (int.TryParse(variable.Value, out value)) builder.AppendLineFormat(" \"{0}\":{1}{2}", variable.Key, value, isLast ? string.Empty : ","); else builder.AppendLineFormat(" \"{0}\":\"{1}\"{2}", variable.Key, variable.Value, isLast ? string.Empty : ","); } builder.Append("}"); return builder.ToString(); }
public static string ToJson(VersionVariables variables) { var builder = new StringBuilder(); builder.AppendLine("{"); var last = variables.Last().Key; foreach (var variable in variables) { var isLast = (variable.Key == last); int value; if (int.TryParse(variable.Value, out value) && variable.Value[0] != '0') // preserve leading zeros for padding builder.AppendLineFormat(" \"{0}\":{1}{2}", variable.Key, value, isLast ? string.Empty : ","); else builder.AppendLineFormat(" \"{0}\":\"{1}\"{2}", variable.Key, variable.Value, isLast ? string.Empty : ","); } builder.Append("}"); return builder.ToString(); }
/// <summary> /// Outputs the profiler information as an HTML table /// </summary> /// <returns>Table containing profiler information</returns> public override string ToHTML() { CompileData(); StringBuilder Builder = new StringBuilder(); Builder.AppendFormat(CultureInfo.InvariantCulture, "<tr><td>{0}</td><td>", CalledFrom); Builder.AppendFormat(CultureInfo.InvariantCulture, "{0}</td><td>{1}ms</td><td>{2}ms</td><td>{3}ms</td><td>{4}ms</td><td>{5}</td></tr>", Query, Times.Sum(), Times.Max(), Times.Min(), string.Format(CultureInfo.InvariantCulture, "{0:0.##}", Times.Average()), Times.Count); foreach (Profiler Child in Children) { Builder.AppendLineFormat(Child.ToHTML()); } return Builder.ToString(); }