How do I format Chinese characters so they fit the columns?
You can use the TextRenderer.MeasureText method from System.Windows.Forms assembly to build the output text basing on string width, instead of characters count.
Here's the util method:
public static string FillWithSpaces(this string text, int width, Font font)
{
while (TextRenderer.MeasureText(text, font).Width < width)
{
text += ' ';
}
return text;
}
And the usage:
var font = new Font("Courier New", 10.0F);
var padding = 340;
var latinPresentation1 = "some text ".FillWithSpaces(padding, font) + "| 23";
var latinPresentation2 = "some longer text".FillWithSpaces(padding, font) + "| 23";
var chinesePresentation1 = "一些文字".FillWithSpaces(padding, font) + "| 23";
var chinesePresentation2 = "一些較長的文字".FillWithSpaces(padding, font) + "| 23";
var result = latinPresentation1 + Environment.NewLine +
latinPresentation2 + Environment.NewLine +
".............................................." + Environment.NewLine +
chinesePresentation1 + Environment.NewLine +
chinesePresentation2;
The solution requires padding parameter (in px) and font used.