📜  红宝石 |字符串 ascii_only?方法

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

红宝石 |字符串 ascii_only?方法

ascii_only?是 Ruby 中的 String 类方法,用于检查只有 ASCII字符的字符串。

示例 1:

#ruby 2.3.1 
     
# Ruby program to demonstrate
# the ascii_only? method
     
# Taking a string and
# using the method
puts "95ruby2364127".ascii_only?
  
puts "\u{1234}".ascii_only?

输出:

true
false

示例 2:

#ruby 2.3.1 
     
# Ruby program to demonstrate
# the ascii_only? method
     
# Taking a string and
# using the method
puts "STRING".ascii_only?
  
puts "\u{7894}".force_encoding("UTF-8").ascii_only?

输出:

true
false