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.


  1. Check if a character is punctuation:

    julia> ispunct('!')

    This example checks if the character '!' is punctuation. The function returns true because '!' is a punctuation character.

  2. Check if a string contains only punctuation:

    julia> ispunct("Hello!")

    The function checks if all elements of the string "Hello!" are punctuation characters. Since the string contains a non-punctuation character ('H'), the function returns false.

  3. Handle empty strings:

    julia> ispunct("")

    In this example, the function returns true for 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.

*Required Field

Checking you are not a robot: