rstrip
rstrip(string, [chars])
Return string
with any trailing whitespace removed. If chars
(a character, or vector or set of characters) is provided, instead remove characters contained in it.
Examples
-
Remove trailing whitespace from a string:
julia> rstrip(" Hello World ") " Hello World"
This example removes the trailing whitespace from the given string.
-
Remove specific characters from the end of a string:
julia> rstrip("Hello World!!", ['!', 'o', 'd']) "Hello World"
It removes the characters '!', 'o', and 'd' from the end of the string.
- Handle an empty string:
julia> rstrip("", 'x') ""
When an empty string is provided, it returns an empty string.
Common mistake example:
julia> rstrip("Hello World", "dlr")
ERROR: MethodError: no method matching rstrip(::String, ::String)
In this example, a string was provided as the second argument instead of a character, vector, or set of characters. Ensure that the second argument is a character or collection of characters to avoid such errors.
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.