Skip to content
Related Articles

Related Articles

Improve Article
Ruby | StringScanner pos= function
  • Last Updated : 10 Dec, 2019

StringScanner#pos=() : pos=() is a StringScanner class method which sets the byte position of the scan pointer.

Syntax: StringScanner.pos=()

Parameter: StringScanner values

Return: sets the byte position of the scan pointer.

Example #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"

Output :

n Sep 12 2018 14:39

9

Example #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"

Output :

llogeeks

eks

My Personal Notes arrow_drop_up
Recommended Articles
Page :