rana123 rana123 - 1 year ago 179
HTML Question

String length in twips java

Is there a way to get the string length in twips?
java implementation would be good.

Answer Source

You can get the width of a char or String, displayed in a certain font, with FontMetrics.stringWidth(). This should be the size in Points. A point is equal to 20 twips.

So this should work:

Font font = new Font("Arial", Font.PLAIN, 10);
FontMetrics fm = new FontMetrics(font);
int widthInTwips = fm.stringWidth("Hello World") * 20;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download