📜  红宝石 | StringScanner 匹配大小函数

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

红宝石 | StringScanner 匹配大小函数

StringScanner#matched_size() :matched_size()是一个 StringScanner 类方法,它返回最近匹配的大小

示例 #1:

Ruby
# Ruby code for StringScanner.matched_size() method
 
# loading StringScanner
require 'strscan'
 
# declaring StringScanner
c = StringScanner.new("Mon Sep 12 2018 14:39")
 
c.match?(/\s+/)
# matched_size() method
puts "String Scanner matched_size form : #{c.matched_size()}\n\n"
 
c.match?(/\w+/)
# matched_size() method
puts "String Scanner matched_size form : #{c.matched_size()}\n\n"


Ruby
# Ruby code for StringScanner.matched_size() method
 
# loading StringScanner
require 'strscan'
 
# declaring StringScanner
c = StringScanner.new("hellogeeks")
 
c.match?(/\s+/)
# matched_size() method
puts "String Scanner matched_size form : #{c.matched_size()}\n\n"
 
c.match?(/\w+/)
# matched_size() method
puts "String Scanner matched_size form : #{c.matched_size()}\n\n"


输出 :

String Scanner matched_size form : 

String Scanner matched_size form : 3

示例 #2:

红宝石

# Ruby code for StringScanner.matched_size() method
 
# loading StringScanner
require 'strscan'
 
# declaring StringScanner
c = StringScanner.new("hellogeeks")
 
c.match?(/\s+/)
# matched_size() method
puts "String Scanner matched_size form : #{c.matched_size()}\n\n"
 
c.match?(/\w+/)
# matched_size() method
puts "String Scanner matched_size form : #{c.matched_size()}\n\n"

输出 :

String Scanner matched_size form : 

String Scanner matched_size form : 10