chop()
是 julia 中的一个内置函数,用于从指定的字符串删除最后一个字符。如果此函数使用 head 和 tail 参数,它将从字符串删除指定数量的第一个头部和最后一个尾部字符。
Syntax:
chop(s::AbstractString, head::Integer, tail::Integer)
Parameters:
- s::AbstractString: Specified string.
- head::Integer: Specified number which removes the starting characters of the string.
- tail::Integer: Specified number which removes the last characters of the string.
Returns: It returns the left part of the specified string after removal.
示例 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))
输出: