📜  红宝石 | String each_grapheme_cluster 方法

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

红宝石 | String each_grapheme_cluster 方法

each_grapheme_cluster是 Ruby 中的 String 类方法,用于将给定字符串中的每个字素簇传递给给定块,如果没有给出块,则返回枚举器。

示例 1:

# Ruby program to demonstrate 
# the each_grapheme_cluster method 
       
# Taking a string and 
# using the method
puts "Ruby".each_grapheme_cluster
puts "String".each_grapheme_cluster.to_a.size

输出:

#
6

示例 2:

# Ruby program to demonstrate 
# the each_grapheme_cluster method 
       
# Taking a string and 
# using the method
puts "Sample".each_grapheme_cluster
puts "Input".each_grapheme_cluster.to_a.size

输出:

#
5