Jump to content

How to calculate the pixel length of a string ?


tmyonline

Recommended Posts

Guys, what I want to do is this.  I'm designing a menu as shown below:

 

Chicken wings (3 pieces) ..............................................$4

Chicken wing, thigh, and breast .....................................$5.95

Chicken combo ...........................................................$12.75

 

I need to fill in the dots [.....................] between the menu item and the price in such a way that the prices align to the left.  Because the menu items are of different lengths, I have to calculate their lengths, convert them into pixels, and subtract them from a fixed number to determine the lengths for the dots.  I tried Barand's suggestion but it didn't work.  But, thanks Barand, I appreciate your help.  Hope to hear from others on this.  Thanks.

Look into sprintf().  You can force a string to a certain length and choose the padding string (such as a dot in your case).  The solution won't be immediately apparent but you should be able to get it with some tinkering.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.