c# - formatting the string to look like a table -


i have string have initialized empty , building string seen below have got preferred output like, whats best mathod of doing this sent email. tak account company names off different length.

string being buit

foreach(string s in array) { emailbody += s + "          success" + environment.newline; } 

ouput of string

companyname    success companyname       success companyname         success companyname           success companyname         success companyname            success companyname          success 

would output below


companyname   |   success companyname   |   success companyname   |   success companyname   |   success companyname   |   success companyname   |   success companyname   |   success 

output of solution given

qxeawgentina                                           success tweseqmechile                                           success vidqwedal                                           success qwebr                                           success doqa_brasil                                           success sedaqqagentina                                           success knaqwertartina                                           success 

padleft nice function use stuff this. this:

stringbuilder mystring = new stringbuilder(); foreach(string s in array) {     mystring.append(s + "success".padleft(15 - s.length) + environment.newline); } emailbody = mystring.tostring(); 

change constant 15 longest companyname have in collection, otherwise padleft throw exception when becomes negative.

(also stringbuilder idea here mentioned in comments)


Comments

Popular posts from this blog

design - Custom Styling Qt Quick Controls -

Unable to remove the www from url on https using .htaccess -