[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(); System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(“smtp.support.com”); smtp.Send(message); solved How do I email the stringbuilder class output … Read more

[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); { builder.Append($”{new string(‘0’, length)}{value}”.Reverse().ToString().Substring(0, length).Reverse().ToString()); } } Then use: StringBuilder builder = new StringBuilder(); builder.AppendPadded(“Hiwor”, 8); … Read more

[Solved] Fixed Array?/ StringBuilder?/ String? which is best way to create a string, if 84 strings to be appended

If by “best” you mean “most memory and/or runtime efficient” then you’re probably best off with a StringBuilder you pre-allocate. (Having looked at the implementation of String.join in the JDK, it uses StringJoiner, which uses a StringBuilder with the default initial capacity [16 chars] with no attempt to avoid reallocation and copying.) You’d sum up … Read more

[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 will delete from start to end-1, hence no IndexOutOfBounds. However, try this: StringBuilder builder = … Read more

[Solved] Merging Lines of text where string ends in a specific condition

Here is a working solution that was developed for (var i = 0; i < Lines.Length; i++) { Builder.Append(Lines[i]); if (Lines[i].EndsWith(” and”) || Lines[i].EndsWith(” of”) || Lines[i].EndsWith(” for”) || Lines[i].EndsWith(” at”) || Lines[i].EndsWith(” the”)) { if (i < (Lines.Length – 1)) { Builder.Append(” “).Append(Lines[i + 1]); i++; } } Builder.AppendLine(“”); } return Builder.ToString(); solved Merging … Read more