Get length of a string in Julia – length() Method

The length() is an inbuilt function in julia which is used to return the length of the specified string with desired starting and end position.

Syntax:
length(S::AbstractString)
or
length(S::AbstractString, i::Integer, j::Integer)

Parameters:

  • S::AbstractString: Specified string
  • i::Integer: Inclusive starting position.
  • i::Integer: Inclusive ending position.

Returns: It returns the length of the specified string with desired starting and end position.

Example 1:




# Julia program to illustrate 
# the use of String length() method
  
# Finding the length of the string
# "Beginner"
println(length("Beginner"))
  
# Finding the length of the string
# "Beginner" from 2nd to 4th position
println(length("Beginner", 2, 4))
  
# Finding the length of the string
# "Beginner" from 2nd to 5th position
println(length("Beginner", 2, 5))
  
# Finding the length of the string
# "w3wiki" 
println(length("w3wiki"))
  
# Finding the length of the string
# "w3wiki" from 2nd to 2nd position
println(length("w3wiki", 2, 2))
  
# Finding the length of the string
# "w3wiki" from 4th to 10th position
println(length("w3wiki", 4, 10))


Output:


Example 2:




# Julia program to illustrate 
# the use of String length() method
   
# Finding the length of the string
# "12345"
println(length("12345"))
   
# Finding the length of the string
# "12345" from 2nd to 4th position
println(length("12345", 2, 4))
   
# Finding the length of the string
# "2468" from 1st to 3rd position
println(length("2468", 2, 3))


Output: