Open In App

Ruby | StringScanner pos= function

Last Updated : 10 Dec, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads