从 Julia 中的字符串中删除单个尾随换行符 – chomp() 方法
chomp()
是 julia 中的内置函数,用于从字符串中删除单个尾随换行符。
Syntax:
chomp(s::AbstractString)
Parameters:
- s::AbstractString: Specified string.
Returns: It returns a new string after removal of a single trailing newline.
示例 1:
# Julia program to illustrate
# the use of String chomp() method
# Getting the removal part of the strings
println(chomp("GFG\n"))
println(chomp("Geeks\n\n"))
println(chomp("Geeks\nforGeeks"))
println(chomp("GFG\ngfg\n"))
输出:
GFG
Geeks
Geeks
forGeeks
GFG
gfg
示例 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"))
输出:
1+2+3
1+2+3
1+2+3
4+5+6
1*2
3*4