📜  红宝石 | StringScanner 定位函数

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

红宝石 | StringScanner 定位函数

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