isascii
isascii(c::Union{Char,AbstractString}) -> Bool
Tests whether a character belongs to the ASCII character set, or whether this is true for all elements of a string.
Examples
-
Check if a character is ASCII:
julia> isascii('A') true
-
Check if a string contains only ASCII characters:
julia> isascii("Hello World!") true
- Handle non-ASCII characters:
julia> isascii('๐') false
Common mistake example:
julia> isascii("ใใใซใกใฏ")
ERROR: MethodError: no method matching isascii(::String)
In this example, the isascii
function is applied to a string containing non-ASCII characters. The isascii
function only works with characters or strings containing ASCII characters, so make sure to check the input before using the function to avoid such errors.
See Also
BigFloat, BigInt, Dict, eltype, fieldtype, Float32, Float64, IntSet, isa, isalnum, isalpha, isascii, iseltype, isequal, isgraph, isimmutable, isinteractive, isleaftype, isnull, ispunct, isspace, issubtype, keytype, Nullable, NullException, promote_type, typeintersect, typejoin, typemax, typemin, typeof, Val, valtype,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.