endswith
endswith(string, suffix | chars)
Returns true if string ends with suffix. If the second argument is a vector or set of characters, tests whether the last character of string belongs to that set.
Examples
-
Check if a string ends with a specific suffix:
julia> endswith("Hello World", "World") trueThis example returns
truebecause the string "Hello World" ends with the suffix "World". -
Check if a string ends with any of the given characters:
julia> endswith("Julia", ['a', 'i']) trueHere, the function returns
truebecause the last character of the string "Julia" is 'a', which is one of the characters provided. -
Handle case sensitivity:
julia> endswith("julia", "JULIA"; ignorecase=true) trueBy setting the
ignorecaseparameter totrue, the function performs a case-insensitive check. In this example, it returnstruebecause "julia" ends with "JULIA" regardless of case.
Common mistake example:
julia> endswith("Hello", "hello")
false
In this example, the function returns false because it performs a case-sensitive check by default. Make sure to consider case sensitivity when using endswith to avoid such mistakes.
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.