Ruby StringScanner string=()函数
StringScanner#string=() : string=()是StringScanner类的一个方法,它将被扫描的字符串改为 “str “并重置扫描器。
语法。StringScanner.string=()
参数。StringScanner的值
返回。”str”
例子 #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)
输出:
String Scanner string= form : hi
hi
例子 #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)
输出:
String Scanner string= form : go
go