Ruby StringScanner matched_size函数
StringScanner#matched_size() : matched_size() 是StringScanner类的一个方法,用于返回最近一次匹配的大小。
语法: StringScanner.match_size()
参数: StringScanner值
返回: 最近一次匹配的大小,否则返回nil。
例子 #1 :
# 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"
输出:
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