📜  红宝石 |字符串 grapheme_clusters 方法

📅  最后修改于: 2022-05-13 01:54:30.259000             🧑  作者: Mango

红宝石 |字符串 grapheme_clusters 方法

grapheme_clusters是 Ruby 中的 String 类方法,用于返回给定字符串中的字形簇数组。

示例 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