红宝石 | StringScanner 定位函数
StringScanner#pos() : pos()是一个 StringScanner 类方法,它返回扫描指针的字节位置
Syntax: StringScanner.pos()
Parameter: StringScanner values
Return: the byte position of the scan pointer
示例 #1:
# Ruby code for StringScanner.pos() method
# loading StringScanner
require 'strscan'
# declaring StringScanner
c = StringScanner.new("Mon Sep 12 2018 14:39")
# pos() method
puts "String Scanner pos form : #{c.pos()}\n\n"
c.terminate()
# pos() method
puts "String Scanner pos form : #{c.pos()}\n\n"
输出 :
String Scanner pos form : 0
String Scanner pos form : 21
示例 #2:
# Ruby code for StringScanner.pos() method
# loading StringScanner
require 'strscan'
# declaring StringScanner
c = StringScanner.new("hellogeeks")
# pos() method
puts "String Scanner pos form : #{c.pos()}\n\n"
c.terminate()
# pos() method
puts "String Scanner pos form : #{c.pos()}\n\n"
输出 :
String Scanner pos form : 0
String Scanner pos form : 10