utf8.len

From Garry's Mod
Jump to: navigation, search
 utf8.len( )

Contents

Description

Returns the number of UTF-8 sequences in the given string between positions startPos and endPos (both inclusive). If it finds any invalid UTF-8 byte sequence, returns false as well as the position of the first invalid byte.

Arguments

string string

The string to calculate the length of.

Arguments

number startPos=1

The starting position to get the length from.

Arguments

number endPos=-1

The ending position to get the length from.

Returns

number

The number of UTF-8 characters in the string. If there are invalid bytes, this will be false.

Returns

number

The position of the first invalid byte. If there were no invalid bytes, this will be nil.

Examples

Example

Demonstrates output of this function compared to string.len when given a string that contains Russian text.

print( string.len( "Мёнём" ) )
print( utf8.len( "Мёнём" ) )

Output:

11 5
Personal tools
Navigation