Ruby StringScanner unscan函数
StringScanner#unscan() : unscan()是StringScanner类的一个方法,它将扫描指针设置到上一个位置。
语法。StringScanner.unscan()
参数。StringScanner的值
返回:将扫描指针设置到之前的位置
例子 #1 :
# Ruby code for StringScanner.unscan() method
# loading StringScanner
require 'strscan'
# declaring StringScanner
c = StringScanner.new("Mon Sep 12 2018 14:39")
c.scan(/\w+/)
# unscan() method
puts "String Scanner unscan form : #{c.unscan()}\n\n"
c.scan(/./)
# unscan() method
puts "String Scanner unscan form : #{c.unscan()}\n\n"
输出:
String Scanner unscan form : #
String Scanner unscan form : #
例子 #2 :
# Ruby code for StringScanner.unscan() method
# loading StringScanner
require 'strscan'
# declaring StringScanner
c = StringScanner.new("h ello geeks")
c.scan(/\w+/)
# unscan() method
puts "String Scanner unscan form : #{c.unscan()}\n\n"
c.scan(/./)
# unscan() method
puts "String Scanner unscan form : #{c.unscan()}\n\n"
输出:
String Scanner unscan form : #
String Scanner unscan form : #
注意:
,由于你的系统中的枚举器或指针值不同,输出可能会有所不同。