Remove a single trailing newline from a string in Julia – chomp() Method
The chomp()
is an inbuilt function in julia which is used to remove a single trailing newline from a string.
Syntax:
chomp(s::AbstractString)Parameters:
- s::AbstractString: Specified string.
Returns: It returns a new string after removal of a single trailing newline.
Example 1:
# Julia program to illustrate # the use of String chomp() method # Getting the removal part of the strings println(chomp( "GFG\n" )) println(chomp( "Beginner\n\n" )) println(chomp( "Beginner\nforBeginner" )) println(chomp( "GFG\ngfg\n" )) |
Output:
GFG Beginner Beginner forBeginner GFG gfg
Example 2:
# Julia program to illustrate # the use of String chomp() method # Getting the removal part of the strings println(chomp( "1 + 2+3\n" )) println(chomp( "1 + 2+3\n\n" )) println(chomp( "1 + 2+3\n4 + 5+6" )) println(chomp( "1 * 2\n\n3 * 4\n" )) |
Output:
1+2+3 1+2+3 1+2+3 4+5+6 1*2 3*4
Contact Us