📜  红宝石 | StringScanner 取消扫描函数

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

红宝石 | StringScanner 取消扫描函数

StringScanner#unscan() : 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 : #

笔记 :
输出可能会因系统的不同枚举器或指针值而异。