How to use the length method of string in Julia

Overview

The length method returns the length of the provided string.

Syntax

length(S::AbstractString)

Parameter

This method takes the String as an argument.

Return value

This method returns an Integer value denoting the length of the provided String.

Example

The code below demonstrates the use of the length method:

# Using length method to get length of "Educative"
println(length("Educative"))
# Using length method to get length of empty string
println(length(""))

Explanation

In the code above:

  • Line 2:. We use the length method to get the length of the String "Educative". We get 9 as the return value.

  • Line 5:. We use the length method to get the length of an Empty String "". We get 0 as the return value.

Free Resources