Answer to Question #63456 in C# for Peter

Question #63456
I have the following toString method which returns 'result' into a textbox

result += "Driver: " + a.getForename() + " " + a.getSurname() + " (" + a.getOccupation() + ")" + "\r\nClaims: " + a.countClaim() + "\r\n";

I want the Claims: (count), to be aligned to the right side of the text box, how can I do this without aligning everything else?

Example:
Driver: (firstname) (surname)(occupation) ...............................Claims: (count)
1
Expert's answer
2016-11-19T11:19:12-0500
you can't do that.
but you can format the string.

int maxLen = 50; // where maxLen is the desired length of the string
string result = new string('.', maxLen);
char[] chr = new char[maxLen];
result.CopyTo(0, chr, 0, result.Length);
result += "Driver: " + a.getForename() + " " + a.getSurname() + " (" + a.getOccupation() + ")" ;
result.CopyTo(0, chr, 0, result.Length);
a.countClaim().ToString().CopyTo(0, chr, chr.Length - a.countClaim().ToString().Length, a.countClaim().ToString().Length);

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
19.11.16, 18:19

We reuploaded the answer, please check.

Peter
19.11.16, 12:59

what are these quot parts appearing for?

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS