红宝石 | StringScanner 重置函数
StringScanner#reset() : reset()是一个 StringScanner 类方法,它重置扫描指针(索引 0)并清除匹配数据。
Syntax: StringScanner.reset()
Parameter: StringScanner values
Return: reset the scan pointer (index 0) and clear matching data.
示例 #1:
# Ruby code for StringScanner.reset() method
# loading StringScanner
require 'strscan'
# declaring StringScanner
c = StringScanner.new("Mon Sep 12 2018 14:39")
# reset() method
c.pos = 2
puts "String Scanner reset form : #{c.reset}\n\n"
# reset() method
c.pos = 7
puts "String Scanner reset form : #{c.reset}\n\n"
输出 :
String Scanner reset form : #
String Scanner reset form : #
示例 #2:
# Ruby code for StringScanner.reset() method
# loading StringScanner
require 'strscan'
# declaring StringScanner
c = StringScanner.new("hellogeeks")
# reset() method
c.pos = 2
puts "String Scanner reset form : #{c.reset}\n\n"
# reset() method
c.pos = 7
puts "String Scanner reset form : #{c.reset}\n\n"
输出 :
String Scanner reset form : #
String Scanner reset form : #
笔记 :
输出值可能会因系统中的指针位置而异。