Ruby StringScanner scan_until函数

Ruby StringScanner scan_until函数

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

语法。StringScanner.scan_until()

参数。StringScanner的值

返回:子串,直到并包括匹配的终点

例子 #1 :

# 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"

输出:

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

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

例子 #2 :

# 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"

输出:

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

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

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程