strlength - Lengths of strings - MATLAB (original) (raw)

Main Content

Syntax

Description

L = strlength([str](#bu46p3t-str)) returns the number of characters in str.

example

Examples

collapse all

Create a string using double quotes. The result is a 1-by-1 string array, or string scalar.

Return the number of characters in str.

Create a string array using the [] operator. str is a 2-by-3 string array that contains six strings.

str = ["Amis","Chekhov","Joyce";"Stein","","Proust"]

str = 2×3 string "Amis" "Chekhov" "Joyce" "Stein" "" "Proust"

Find the length of each string in str. Use strlength, not length, to determine the number of characters in each element of a string array.

Create a character vector. To return the number of characters in the character vector, use the strlength function.

chr = 'The rain in Spain.'

chr = 'The rain in Spain.'

Input Arguments

collapse all

Input text, specified as a string array, a character vector, or a cell array of character vectors.

Tips

Algorithms

strlength counts the number of code units in text. Code units are bit sequences for encoding characters of a character encoding system. In some character encodings, such as UTF-16, there are some characters that are encoded with multiple code units.

If you have a string or a character vector that contains such characters, then the number of code units is greater than the number of characters.

length(C) also returns the number of code units when C is a character vector.

Extended Capabilities

expand all

Thestrlength function fully supports tall arrays. For more information, see Tall Arrays.

Version History

Introduced in R2016b