📌  相关文章
📜  去除Julia中字符串的开始和结束字符——chop()方法

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

chop()是 julia 中的一个内置函数,用于从指定的字符串删除最后一个字符。如果此函数使用 head 和 tail 参数,它将从字符串删除指定数量的第一个头部和最后一个尾部字符。

示例 1:

# Julia program to illustrate 
# the use of String chop() method
  
# Getting the removal part of the strings
println(chop("GeeksforGeeks"))
println(chop("GeeksforGeeks", head = 1, tail = 2))
println(chop("GeeksforGeeks", head = 5, tail = 5))
println(chop("GeeksforGeeks", head = 5, tail = 8))
println(chop("GeeksforGeeks", head = 13, tail = 13))

输出:

示例 2:

# Julia program to illustrate 
# the use of String chop() method
  
# Getting the removal part of the strings
println(chop("1-2-3-4-5-6"))
println(chop("1-2-3-4-5-6", head = 1, tail = 2))
println(chop("1-2-3-4-5-6", head = 3, tail = 5))
println(chop("1-2-3-4-5-6", head = 5, tail = 6))
println(chop("1-2-3-4-5-6", head = 11, tail = 11))

输出: