graphemes

graphemes(s) -> iterator over substrings of s

Returns an iterator over substrings of s that correspond to the extended graphemes in the string, as defined by Unicode UAX #29. (Roughly, these are what users would perceive as single characters, even though they may contain more than one codepoint; for example a letter combined with an accent mark is a single grapheme.)

Examples

  1. Iterate over graphemes in a string:

    julia> for g in graphemes("Hello")
              println(g)
          end
    H
    e
    l
    l
    o

    This example iterates over each grapheme in the string "Hello" and prints them individually.

  2. Count the number of graphemes in a string:

    julia> count(graphemes("Julia is awesome!"))
    16

    It counts the number of graphemes in the given string.

  3. Create an array of graphemes from a string:
    julia> arr = collect(graphemes("Julia"))
    5-element Array{String,1}:
    "J"
    "u"
    "l"
    "i"
    "a"

    This example converts the graphemes in the string "Julia" into an array.

Common mistake example:

julia> graphemes("๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ")
ERROR: MethodError: no method matching graphemes(::String)

In this example, the function graphemes does not support grapheme extraction from a string containing Unicode grapheme clusters. It is important to note that graphemes works with extended graphemes, not grapheme clusters.

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.

*Required Field
Details

Checking you are not a robot: