Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

strlength

Length of strings in string array

Syntax

Description

example

L = strlength(str) returns the number of characters in each element of the input string array. The size of L is the same as the size of str.

Examples

collapse all

str = string('Hello, World');
L = strlength(str)
L =

    12

str = string({'Amy','Charles','Joan';'Mark','','Sarah'})
str = 

  2×3 string array

    "Amy"     "Charles"    "Joan" 
    "Mark"    ""           "Sarah"

L = strlength(str)
L =

     3     7     4
     4     0     5

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.

L = strlength(chr)
L =

    18

Related Examples

Input Arguments

collapse all

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

More About

collapse all

Tall Array Support

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

Tips

To find the number of characters in each element of str, use strlength. To find the length of the largest array dimension of str, use the length function.

Algorithms

strlength counts the number of code units in a string. 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.

See Also

| | | | |

Introduced in R2016b

Was this topic helpful?