Get a substring of specified length from a string in Julia – SubString() Method
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 # "Beginner" from starting index 1 # to ending index 3 println(SubString( "Beginner" , 1 , 3 )) # Finding a part of the parent string # "w3wiki" from starting index 5 # to ending index 10 println(SubString( "w3wiki" , 5 , 10 )) # Finding a part of the parent string # "Beginner" with unitrange 2 println(SubString( "Beginner" , 2 )) # Finding a part of the parent string # "w3wiki" with unit range 6 println(SubString( "w3wiki" , 6 )) |
Output:
Gee sforGe eeks forBeginner
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