isdigit
isdigit(c::Union{Char,AbstractString}) -> Bool
Tests whether a character is a numeric digit (0-9), or whether this is true for all elements of a string.
Examples
-
Check if a character is a digit:
julia> isdigit('5') true
This example checks if the character '5' is a numeric digit.
-
Check if a character is not a digit:
julia> isdigit('x') false
It returns
false
for a non-digit character. -
Check if all characters in a string are digits:
julia> isdigit("12345") true
It returns
true
if all characters in the string are numeric digits. - Check if any character in a string is not a digit:
julia> isdigit("12x34") false
It returns
false
if any character in the string is not a digit.
Common mistake example:
julia> isdigit("abc123")
ERROR: MethodError: no method matching isdigit(::String)
In this example, the isdigit
function is called with a string as an argument. However, the isdigit
function only accepts a Char
or AbstractString
as input. Ensure that you pass a character or a string to the isdigit
function to avoid such errors.
See Also
digits, inf, isdigit, iseven, isfinite, isless, islower, isnumber, isodd, isprime, isqrt, issorted, issubnormal, isxdigit, nan,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.