📜  Julia中从字符串中获取指定长度的子字符串——SubString()方法

📅  最后修改于: 2021-11-25 04:41:58             🧑  作者: Mango

SubString()是 julia 中的一个内置函数,用于返回指定父字符串si : jr范围内的一部分,其中 i、j 和 r 作为参数给出。

示例 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