Question : How to create a left justified value using srring.format?

hi,

I have the below code which creates a value right justified. The messagebox shows the value as  "           123456789" with leading spaces.

string fieldValue = "123456789";
int FieldLength = 20;
 fieldValue = string.Format(string.Format("{{0,{0}}}", FieldLength), fieldValue);
MessageBox.Show("fieldValue: " + fieldValue);

The messagebox shows the value as  "           123456789" with leading spaces so the value is exactly of length equal to FieldLength .
I need to change the code to create the value left justified. Can anybody please help how to do this?

Thanks.

Answer : How to create a left justified value using srring.format?

Or, it didn't attach the code!
1:
2:
3:
4:
int FieldLength = 20;
string s = "123456789";
string format = "{0, -" + FieldLength + "}";
Console.WriteLine(String.Format(format, s));
Random Solutions  
 
programming4us programming4us