Ruby StringScanner search_full函数

Ruby StringScanner search_full函数

StringScanner#search_full() : search_full()是一个StringScanner方法,它扫描字符串直到模式被匹配。

语法。StringScanner.search_full()

参数。StringScanner值

pattern

advance_pointer

return_pointer

返回:如果return_string_p为真,则匹配的字符串,否则返回提前的字节数

例子 #1 :

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

输出:

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

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

例子 #2 :

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

输出:

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

String Scanner result of c.search_full() form : 2

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程