Open In App
Related Articles

Remove end characters from strings in Julia – strip(), lstrip() and rstrip() Methods

Improve Article
Improve
Save Article
Save
Like Article
Like

The strip() is an inbuilt function in julia which is used to remove leading and trailing characters from the specified string str. These removing elements is specified by given characters chars.

Syntax:
strip(str::AbstractString, chars)

Parameters:

  • str::AbstractString: Specified string.
  • chars: Specified characters.

Returns: It returns a stripped part of the given string.

Example:




# Julia program to illustrate 
# the use of strip() method
   
# Getting a stripped part of the given string.
println(strip("Geeks", ['s']))
println(strip("GFG", ['G']))
println(strip("1 + 2+3 + 4", ['+']))
println(strip("+1 + 2+3 + 4+", ['+']))

Output:

Geek
F
1+2+3+4
1+2+3+4

lstrip()

The lstrip() is an inbuilt function in julia which is used to remove leading characters from the specified string str. These removing elements is specified by given characters chars.

Syntax:
lstrip(str::AbstractString, chars)

Parameters:

  • str::AbstractString: Specified string.
  • chars: Specified characters.

Returns: It returns a stripped part of the given string.

Example:




# Julia program to illustrate 
# the use of lstrip() method
   
# Getting a stripped part of the given string.
println(lstrip("Geek", ['G']))
println(lstrip("GFG", ['G']))
println(lstrip("1 + 2+3 + 4+", ['+']))
println(lstrip("+1 + 2+3 + 4", ['+']))

Output:

eek
FG
1+2+3+4+
1+2+3+4

rstrip()

The rstrip() is an inbuilt function in julia which is used to remove trailing characters from the specified string str. These removing elements is specified by given characters chars.

Syntax:
rstrip(str::AbstractString, chars)

Parameters:

  • str::AbstractString: Specified string.
  • chars: Specified characters.

Returns: It returns a stripped part of the given string.

Example:




# Julia program to illustrate 
# the use of rstrip() method
   
# Getting a stripped part of the given string.
println(rstrip("Geek", ['G']))
println(rstrip("GFG", ['G']))
println(rstrip("1 + 2+3 + 4+", ['+']))
println(rstrip("+1 + 2+3 + 4", ['+']))

Output:

Geek
GF
1+2+3+4
+1+2+3+4

Last Updated : 01 Apr, 2020
Like Article
Save Article
Similar Reads