Get a substring of specified length from a string in Julia – SubString() Method
Last Updated :
26 Mar, 2020
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:
println(SubString( "Geeks" , 1 , 3 ))
println(SubString( "GeeksforGeeks" , 5 , 10 ))
println(SubString( "Geeks" , 2 ))
println(SubString( "GeeksforGeeks" , 6 ))
|
Output:
Gee
sforGe
eeks
forGeeks
Example 2:
println(SubString( "12345" , 1 , 3 ))
println(SubString( "123456789" , 5 , 8 ))
println(SubString( "2468" , 2 ))
|
Output:
123
5678
468
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...