Ruby StringScanner pos函数
StringScanner#pos() : pos()是StringScanner类的一个方法,用于返回扫描指针的字节位置
语法。StringScanner.pos()
参数。StringScanner的值
返回:扫描指针的字节位置
例子 #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