Skip to content
Related Articles

Related Articles

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

StringScanner#charpos() : charpos() is a StringScanner class method which returns the character position of the scan pointer.

Syntax: StringScanner.charpos()

Parameter: StringScanner values

Return: the character position of the scan pointer

Example #1 :






# Ruby code for StringIO.charpos() method
  
# loading StringIO
require 'strscan'
  
# declaring StringIO 
c = StringScanner.new("Fri Dec 12 1975 14:39")
  
# charpos() method
puts "String Scanner charpos form : #{c.charpos()}\n\n"

Output :

String Scanner charpos form : 0

Example #2 :




# Ruby code for StringIO.charpos() method
  
# loading StringIO
require 'strscan'
  
# declaring StringIO 
c = StringScanner.new("hellogeeks")
  
# charpos() method
puts "String Scanner charpos form : #{c.charpos()}\n\n"

Output :

String Scanner charpos form : 0
My Personal Notes arrow_drop_up
Recommended Articles
Page :