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# "Geeks" from starting index 1# to ending index 3println(SubString("Geeks", 1, 3)) # Finding a part of the parent string# "GeeksforGeeks" from starting index 5# to ending index 10println(SubString("GeeksforGeeks", 5, 10)) # Finding a part of the parent string# "Geeks" with unitrange 2println(SubString("Geeks", 2)) # Finding a part of the parent string# "GeeksforGeeks" with unit range 6println(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 3println(SubString("12345", 1, 3)) # Finding a part of the parent string# "123456789" from starting index 5# to ending index 8println(SubString("123456789", 5, 8)) # Finding a part of the parent string# "2468" with unitrange 2println(SubString("2468", 2)) |
Output:
123 5678 468





Please Login to comment...