📜  红宝石 | StringScanner 检查函数

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

红宝石 | StringScanner 检查函数

StringScanner#check() : check()是一个 StringScanner 类方法,它返回扫描将返回的值,而不推进扫描指针

示例 #1:

# Ruby code for StringIO.check() method
  
# loading StringIO
require 'strscan'
  
# declaring StringIO 
c = StringScanner.new("Fri Dec 12 1975 14:39")
  
# check() method
puts "String Scanner check form : #{c.check /Fri/}\n\n"

输出 :

String Scanner check form : Fri

示例 #2:

# Ruby code for StringIO.check() method
  
# loading StringIO
require 'strscan'
  
# declaring StringIO 
c = StringScanner.new("hellogeeks")
  
# check() method
puts "String Scanner check form : #{c.check /hel/}\n\n"

输出 :

String Scanner check form : hel