Ruby StringScanner scan_until函数
StringScanner#scan_until() : scan_until()是StringScanner类的一个方法,它扫描字符串,直到模式被匹配。
语法。StringScanner.scan_until()
参数。StringScanner的值
返回:子串,直到并包括匹配的终点
例子 #1 :
# Ruby code for StringScanner.scan_until() method
# loading StringScanner
require 'strscan'
# declaring StringScanner
c = StringScanner.new("Mon Sep 12 2018 14:39")
# scan_until() method
c.scan_until(/\w+/)
puts "String Scanner result of c.scan_until() form : #{c.pos()}\n\n"
# scan_until() method
c.scan_until(/\s+/)
puts "String Scanner result of c.scan_until() form : #{c.pos()}\n\n"
输出:
String Scanner result of c.scan_until() form : 3
String Scanner result of c.scan_until() form : 4
例子 #2 :
# Ruby code for StringScanner.scan_until() method
# loading StringScanner
require 'strscan'
# declaring StringScanner
c = StringScanner.new("h ello geeks")
# scan_until() method
c.scan_until(/\w+/)
puts "String Scanner result of c.scan_until() form : #{c.pos()}\n\n"
# scan_until() method
c.scan_until(/\s+/)
puts "String Scanner result of c.scan_until() form : #{c.pos()}\n\n"
输出:
String Scanner result of c.scan_until() form : 1
String Scanner result of c.scan_until() form : 2