StringBuilderExtention.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace EVCB_OCPP.WSServer.Helper;
  7. public static class StringBuilderExtention
  8. {
  9. private readonly static char[] m_CrCf;
  10. static StringBuilderExtention()
  11. {
  12. m_CrCf = "\r\n".ToArray();
  13. }
  14. /// <summary>
  15. /// Appends in the format with CrCf as suffix.
  16. /// </summary>
  17. /// <param name="builder">The builder.</param>
  18. /// <param name="format">The format.</param>
  19. /// <param name="arg">The arg.</param>
  20. public static void AppendFormatWithCrCf(this StringBuilder builder, string format, object arg)
  21. {
  22. builder.AppendFormat(format, arg);
  23. builder.Append(m_CrCf);
  24. }
  25. /// <summary>
  26. /// Appends in the format with CrCf as suffix.
  27. /// </summary>
  28. /// <param name="builder">The builder.</param>
  29. /// <param name="format">The format.</param>
  30. /// <param name="args">The args.</param>
  31. public static void AppendFormatWithCrCf(this StringBuilder builder, string format, params object[] args)
  32. {
  33. builder.AppendFormat(format, args);
  34. builder.Append(m_CrCf);
  35. }
  36. /// <summary>
  37. /// Appends with CrCf as suffix.
  38. /// </summary>
  39. /// <param name="builder">The builder.</param>
  40. /// <param name="content">The content.</param>
  41. public static void AppendWithCrCf(this StringBuilder builder, string content)
  42. {
  43. builder.Append(content);
  44. builder.Append(m_CrCf);
  45. }
  46. /// <summary>
  47. /// Appends with CrCf as suffix.
  48. /// </summary>
  49. /// <param name="builder">The builder.</param>
  50. public static void AppendWithCrCf(this StringBuilder builder)
  51. {
  52. builder.Append(m_CrCf);
  53. }
  54. }