ispunct
ispunct(c::Union{Char,AbstractString}) -> Bool
Tests whether a character belongs to the Unicode general category Punctuation, i.e. a character whose category code begins with 'P'. For strings, tests whether this is true for all elements of the string.
Examples
-
Check if a character is punctuation:
julia> ispunct('!') trueThis example checks if the character
'!'is punctuation. The function returnstruebecause'!'is a punctuation character. -
Check if a string contains only punctuation:
julia> ispunct("Hello!") falseThe function checks if all elements of the string
"Hello!"are punctuation characters. Since the string contains a non-punctuation character ('H'), the function returnsfalse. -
Handle empty strings:
julia> ispunct("") trueIn this example, the function returns
truefor an empty string since there are no non-punctuation characters present.
Common mistake example:
julia> ispunct('A')
ERROR: MethodError: no method matching ispunct(::Char)
In this example, the function call ispunct('A') results in an error because the character 'A' is not a punctuation character. Remember that ispunct only accepts characters or strings as input.
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.