Name
CharWidth -- return byte width of character (V7.0)
Synopsis
w = CharWidth(s$[, pos, encoding])
Function
Calculates the byte width of the character at position pos inside s$. The position must be specified in characters, not in bytes. The pos argument is optional and defaults to 0, i.e. the beginning of the string, if omitted.

The optional encoding parameter can be used to set the character encoding to use. This defaults to the default string encoding set using SetDefaultEncoding(). See Character encodings for details.

In the UTF-8 character encoding a single character may need a storage space of up to 4 bytes. In the ISO 8859-1 character encoding there is no difference between byte and character sizes. Hence, it doesn't really make sense to call this function with the character encoding set to #ENCODING_ISO8859_1.

Inputs
s$
input string
pos
optional: index, in characters, of the character whose width should be calculated
encoding
optional: character encoding to use (defaults to default string encoding)
Results
w
byte width of character at the specified position
Example
w = CharWidth("ä")
Print(w)
If Hollywood is in Unicode mode, this will return 2 because the "ä" character takes up 2 bytes in UTF-8 code space. In ISO 8859-1 there is no difference between characters and bytes, so 1 will be returned in that case.

Show TOC