Open In App

Get a substring of specified length from a string in Julia – SubString() Method

Last Updated : 26 Mar, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The SubString() is an inbuilt function in julia which is used to return a part of the specified parent string s within range i:j or r, where i, j and r is given as the parameter.

Syntax:
SubString(string::AbstractString, i::Integer, j::Integer)
or
SubString(string::AbstractString, r::UnitRange)

Parameters:

  • string: Specified parent string
  • i: Specified starting index
  • j: Specified last index
  • r: Specified unit range

Returns: It returns a part of the specified parent string s within range i:j or r, where i, j and r is given as the parameter.

Example 1:




# Julia program to illustrate 
# the use of String SubString() method
  
# Finding a part of the parent string
# "Geeks" from starting index 1
# to ending index 3
println(SubString("Geeks", 1, 3))
  
# Finding a part of the parent string
# "GeeksforGeeks" from starting index 5
# to ending index 10
println(SubString("GeeksforGeeks", 5, 10))
  
# Finding a part of the parent string
# "Geeks" with unitrange 2
println(SubString("Geeks", 2))
  
# Finding a part of the parent string
# "GeeksforGeeks" with unit range 6
println(SubString("GeeksforGeeks", 6))


Output:

Gee
sforGe
eeks
forGeeks

Example 2:




# Julia program to illustrate 
# the use of String SubString() method
   
# Finding a part of the parent string
# "12345" from starting index 1
# to ending index 3
println(SubString("12345", 1, 3))
   
# Finding a part of the parent string
# "123456789" from starting index 5
# to ending index 8
println(SubString("123456789", 5, 8))
   
# Finding a part of the parent string
# "2468" with unitrange 2
println(SubString("2468", 2))


Output:

123
5678
468


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads