红宝石 |字符串 grapheme_clusters 方法
grapheme_clusters是 Ruby 中的 String 类方法,用于返回给定字符串中的字形簇数组。
Syntax: str.grapheme_clusters
Parameters: Here, str is the given string.
Returns: An array of grapheme clusters.
示例 1:
# Ruby program to demonstrate
# the grapheme_clusters method
# Taking a string and
# using the method
puts "Sample".grapheme_clusters
puts "Program".grapheme_clusters
输出:
S
a
m
p
l
e
P
r
o
g
r
a
m
示例 2:
# Ruby program to demonstrate
# the grapheme_clusters method
# Taking a string and
# using the method
puts "Ruby\n".grapheme_clusters
puts "String".grapheme_clusters
输出:
R
u
b
y
S
t
r
i
n
g