红宝石 | StringScanner 存在吗?函数
StringScanner#exist?() :exist?()是一个 StringScanner 类方法,如果模式存在则返回指针的值。
Syntax: StringScanner.exist?()
Parameter: StringScanner values
Return: the value of pointer – if the pattern exists otherwise return nil.
示例 #1:
Ruby
# Ruby code for StringIO.exist?() method
# loading StringIO
require 'strscan'
# declaring StringIO
c = StringScanner.new("Fri Dec 12 2018 14:39")
# exist?() method
puts "String Scanner exist? form : #{c.exist? /2018/}\n\n"
Ruby
# Ruby code for StringIO.exist?() method
# loading StringIO
require 'strscan'
# declaring StringIO
c = StringScanner.new("hellogeeks")
# exist?() method
puts "String Scanner exist? form : #{c.exist? /ge/}\n\n"
输出 :
String Scanner exist? form : 15
示例 #2:
红宝石
# Ruby code for StringIO.exist?() method
# loading StringIO
require 'strscan'
# declaring StringIO
c = StringScanner.new("hellogeeks")
# exist?() method
puts "String Scanner exist? form : #{c.exist? /ge/}\n\n"
输出 :
String Scanner exist? form : 7