📜  红宝石 | StringScanner 指针=函数

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

红宝石 | StringScanner 指针=函数

StringScanner#pointer=() : pointer=()是一个 StringScanner 类方法,它设置扫描指针的字节位置。

示例 #1:

# Ruby code for StringScanner.pointer=() method
  
# loading StringScanner
require 'strscan'
  
# declaring StringScanner 
c = StringScanner.new("Mon Sep 12 2018 14:39")
  
# pointer=() method
c.pointer = 2
  
puts "#{c.rest}\n\n"
  
# pointer=() method
c.pointer = 20
  
puts "#{c.rest}\n\n"

输出 :

n Sep 12 2018 14:39

9

示例 #2:

# Ruby code for StringScanner.pointer=() method
  
# loading StringScanner
require 'strscan'
  
# declaring StringScanner 
c = StringScanner.new("hellogeeks")
  
# pointer=() method
c.pointer = 2
  
puts "#{c.rest}\n\n"
  
# pointer=() method
c.pointer = 7
  
puts "#{c.rest}\n\n"

输出 :

llogeeks

eks