红宝石 | StringScanner pos=函数
StringScanner#pos=() : pos=()是一个 StringScanner 类方法,它设置扫描指针的字节位置。
Syntax: StringScanner.pos=()
Parameter: StringScanner values
Return: sets 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
c.pos = 2
puts "#{c.rest}\n\n"
# pos=() method
c.pos = 20
puts "#{c.rest}\n\n"
输出 :
n Sep 12 2018 14:39
9
示例 #2:
# Ruby code for StringScanner.pos=() method
# loading StringScanner
require 'strscan'
# declaring StringScanner
c = StringScanner.new("hellogeeks")
# pos=() method
c.pos = 2
puts "#{c.rest}\n\n"
# pos=() method
c.pos = 7
puts "#{c.rest}\n\n"
输出 :
llogeeks
eks