Open In App

Remove starting and ending characters of string in Julia – chop() Method

The chop() is an inbuilt function in julia which is used to remove the last character from the specified string. If this function use head and tail parameter, it removes the specified number of first head and the last tail characters from the string.

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.



Example 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))

Output:

Example 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))

Output:


Article Tags :