Purpose
Returns the number of bytes in a string for a given character set (charset). You can call this function from the MapBasic window in MapInfo Pro.
Syntax
StringByteLength( string_expr, charset )
string_expr is a string of characters for computing number of bytes used by this string.
charset is a string representing the character set used with the string_expr. See Charset clause for a list of valid character sets.
Return Value
Integer
Description
This function returns the number of bytes in a string for a given charset. It is sometimes useful to know the number of bytes needed to represent a string with multi-byte character sets (for example: UTF-8 or WindowsJapanese). A string with UTF-8 charset can use up to 4 bytes to represent characters.
If a non-string value is passed for string_expr or charset, an error is thrown.
If an invalid charset is passed for charset, an error is thrown.
If no value is passed for charset, an error is thrown.
Examples
print StringByteLength("滋賀県草津市草津", "UTF-16")
The above example returns 16 since these eight Japanese characters use two byes each when using UTF-16.
print StringByteLength("滋賀県草津市草津", "UTF-8")
The above example returns 24 since these eight Japanese characters use three bytes each in UTF-8.
print StringByteLength("滋賀県草津市草津", "WindowsJapanese")
The above example returns 16 as these eight Japanese characters use two bytes each in WindowsJapanese.
Print StringByteLength("قبل البدء في استعمال", "UTF-8")
The above example returns 37 as these twenty Arabic characters use 1- 3 bytes each in UTF-8.
Example for usage:
When saving a table (e.g.: World.tab) in WindowsArabic charset to a new table using UTF-8 charset, you can calculate the maximum width needed for a column by:
select Max(StringByteLength(World.Col1, "UTF-8")) from World
See Also: