Name
TextWidth -- return the width of a string
Synopsis
width = TextWidth(string$[, encoding])
Function
This function returns the width of the text specified by string$ if it was rendered on the display. So it takes care of the currently selected font as well as the font style.

Please note: This function returns the cursor advancement of the text. This is often less than the text actually occupies when rendered to the display. If you need detailed information about the real extent of a text, please use the function TextExtent() instead.

Starting with Hollywood 4.7 there is an optional argument that can be used to specify the character encoding inside string$. This defaults to the text library default encoding set by SetDefaultEncoding(). See SetDefaultEncoding for details.

Inputs
string$
source text
encoding
optional: character encoding used by string$ (defaults to the text library encoding specified in the last call to SetDefaultEncoding()) (V4.7)
Results
width
width of the text
Example
width = TextWidth("Hello World")
pos = (640 - width) / 2
Locate(pos, 0)
Print("Hello World")
The above code centers the text "Hello World" horizontally on a 640 pixel-wide display.

Show TOC