SubString()
是 julia 中的一个内置函数,用于返回指定父字符串s在i : j或r范围内的一部分,其中 i、j 和 r 作为参数给出。
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.
示例 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))
输出:
Gee
sforGe
eeks
forGeeks
示例 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))
输出:
123
5678
468