红宝石 | StringScanner skip_until函数
StringScanner#skip_until() :skip_until()是一个 StringScanner 类方法,它返回先进的字节数,如果没有找到匹配项,则返回 nil。
Syntax: StringScanner.skip_until()
Parameter: StringScanner values
pattern
Return: the number of bytes advanced, or nil if no match was found.
示例 #1:
# Ruby code for StringScanner.skip_until() method
# loading StringScanner
require 'strscan'
# declaring StringScanner
c = StringScanner.new("Mon Sep 12 2018 14:39")
# skip_until() method
c.skip_until(/12/)
puts "String Scanner skip_until form : #{c.pos()}\n\n"
# skip_until() method
c.skip_until(/./)
puts "String Scanner skip_until form : #{c.pos()}\n\n"
输出 :
String Scanner skip_until form : 10
String Scanner skip_until form : 11
示例 #2:
# Ruby code for StringScanner.skip_until() method
# loading StringScanner
require 'strscan'
# declaring StringScanner
c = StringScanner.new("h ello geeks")
# skip_until() method
c.skip_until(/12/)
puts "String Scanner skip_until form : #{c.pos()}\n\n"
# skip_until() method
c.skip_until(/./)
puts "String Scanner skip_until form : #{c.pos()}\n\n"
输出 :
String Scanner skip_until form : 0
String Scanner skip_until form : 1