chomp
chomp(string)
Remove a trailing newline from a string.
Examples
julia> chomp("Hello World\n")
"Hello World"
julia> chomp("Julia\n")
"Julia"
julia> chomp("No trailing newline")
"No trailing newline"
-
Remove trailing newline from a string with a newline:
julia> chomp("Hello World\n") "Hello World"
This example removes the trailing newline character from the string "Hello World\n".
-
Remove trailing newline from a string with only a newline:
julia> chomp("Julia\n") "Julia"
It removes the trailing newline character from the string "Julia\n".
- Handle strings without a trailing newline:
julia> chomp("No trailing newline") "No trailing newline"
This example shows that if the string doesn't have a trailing newline, it remains unchanged.
Common mistake example:
julia> chomp(123)
ERROR: MethodError: no method matching chomp(::Int64)
In this example, the chomp()
function is called with an argument that is not a string. The chomp()
function only works with strings, so ensure that the argument passed is a string.
See Also
ascii, base64decode, Base64DecodePipe, base64encode, Base64EncodePipe, bin, bits, bytestring, charwidth, chomp, chop, chr2ind, contains, endswith, escape_string, graphemes, ind2chr, iscntrl, istext, isupper, isvalid, join, lcfirst, lowercase, lpad, lstrip, normalize_string, num2hex, parseip, randstring, readuntil, replace, repr, rpad, rsplit, rstrip, search, searchindex, split, startswith, string, stringmime, strip, strwidth, summary, takebuf_string, ucfirst, unescape_string, uppercase, utf16, utf32, utf8, wstring,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.