Skip to content
Related Articles

Related Articles

Improve Article

Ruby | StringScanner string=() function

  • Last Updated : 10 Dec, 2019

StringScanner#string=() : string=() is a StringScanner class method which Changes the string being scanned to “str” and resets the scanner

Syntax: StringScanner.string=()

Parameter: StringScanner values

Return: “str”

Example #1 :






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

Output :

String Scanner string= form : hi

hi

Example #2 :




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

Output :

String Scanner string= form : go

go
My Personal Notes arrow_drop_up
Recommended Articles
Page :