Ruby | StringScanner scan_until function

StringScanner#scan_until() : scan_until() is a StringScanner class method which scans the string until the pattern is matched

Syntax: StringScanner.scan_until()

Parameter: StringScanner values

Return: the substring up to and including the end of the match

Example #1 :



filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby code for StringScanner.scan_until() method
  
# loading StringScanner
require 'strscan'
  
# declaring StringScanner 
c = StringScanner.new("Mon Sep 12 2018 14:39")
   
# scan_until() method
c.scan_until(/\w+/)
  
puts "String Scanner result of c.scan_until() form : #{c.pos()}\n\n"
  
# scan_until() method
c.scan_until(/\s+/)
  
puts "String Scanner result of c.scan_until() form : #{c.pos()}\n\n"

chevron_right


Output :

String Scanner result of c.scan_until() form : 3

String Scanner result of c.scan_until() form : 4

Example #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby code for StringScanner.scan_until() method
  
# loading StringScanner
require 'strscan'
  
# declaring StringScanner 
c = StringScanner.new("h ello geeks")
   
# scan_until() method
c.scan_until(/\w+/)
  
puts "String Scanner result of c.scan_until() form : #{c.pos()}\n\n"
  
  
# scan_until() method
c.scan_until(/\s+/)
  
puts "String Scanner result of c.scan_until() form : #{c.pos()}\n\n"

chevron_right


Output :

String Scanner result of c.scan_until() form : 1

String Scanner result of c.scan_until() form : 2
My Personal Notes arrow_drop_up

Recommended Posts:

    Article Tags :

    Be the First to upvote.


    Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.