Name
ByteOffset -- convert character to byte offset (V7.0)
Synopsis
boff = ByteOffset(s$, coff[, encoding])
Function
This function returns the byte offset of the character at the offset specified by coff inside string s$. This offset is in characters, starting from 0.

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.

To convert a byte offset into a character offset use the CharOffset() function. See CharOffset for details.

Inputs
s$
input string
coff
character offset to be mapped to a byte offset (starting from 0)
encoding
optional: character encoding to use (defaults to default string encoding)
Results
boff
byte offset of the specified character
Example
boff = ByteOffset("äöü", 2)
Print(boff)
If Hollywood is in Unicode mode, this will return 4 because the two characters before the "ü" take up 2 bytes each in UTF-8 code space. In ISO 8859-1 there is no difference between characters and bytes, so 2 will be returned in that case.

Show TOC