Tag stringbuilder

[Solved] How do I email the stringbuilder class output using C# [closed]

Thanks Vladimir Arustamian for the research pointer…this is my solution… StringBuilder errMsg = new StringBuilder(); errMsg.AppendLine(); errMsg.AppendLine(“*************************”); errMsg.AppendLine(“TimeStamp: ” + System.DateTime.Now.ToString()); errMsg.AppendLine(errorMessage); errMsg.AppendLine(“*************************”); sw.WriteLine(errMsg.ToString()); System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); message.To.Add(System.Configuration.ConfigurationManager.AppSettings[“siteAdmin”]); message.Subject = “Failure”; message.From = new System.Net.Mail.MailAddress(“[email protected]”); message.Body = errMsg.ToString();…

[Solved] Modify non immutable object, java

I have one StringBuilder, a non immutable object and if I use a method on the object it will return me a new value of the object with the same reference object. Not always will a method return you the…

[Solved] Build the string dynamically based on the length in c#

Firstly define an extension method for StringBuilder: public static class StringBuilderExtensions { public static void AppendPadded(this StringBuilder builder, string value, int length); { builder.Append($”{value}{new string(‘ ‘, length)}”.Substring(0, length)); } public static void AppendPadded(this StringBuilder builder, int value, int length); {…

[Solved] StringBuilder delete methods [closed]

I’d say this is fine. The intent is different. Lets try this for example: String builder sb = new StringBuilder(); sb.append(“hello”).append(“hello”); sb.delete(0,5); sb.toString(); It prints “hello”. Had you read the documentation, you’d see that the end is non-inclusive, meaning it…