Open In App

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

Improve
Improve
Like Article
Like
Save
Share
Report

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
# "Geeks"
println(length("Geeks"))
  
# Finding the length of the string
# "Geeks" from 2nd to 4th position
println(length("Geeks", 2, 4))
  
# Finding the length of the string
# "Geeks" from 2nd to 5th position
println(length("Geeks", 2, 5))
  
# Finding the length of the string
# "GeeksforGeeks" 
println(length("GeeksforGeeks"))
  
# Finding the length of the string
# "GeeksforGeeks" from 2nd to 2nd position
println(length("GeeksforGeeks", 2, 2))
  
# Finding the length of the string
# "GeeksforGeeks" from 4th to 10th position
println(length("GeeksforGeeks", 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:



Last Updated : 26 Mar, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads