StringScanner#peek() : peek() es un método de la clase StringScanner que devuelve una string correspondiente a string[pos, len].
Sintaxis: StringScanner.peek()
Parámetro: valores de StringScanner
len – longitud del valor de la stringDevuelve: una string correspondiente a string[pos, len]
Ejemplo 1 :
# Ruby code for StringScanner.peek() method # loading StringScanner require 'strscan' # declaring StringScanner c = StringScanner.new("Mon Sep 12 2018 14:39") # peek() method puts "String Scanner peek form : #{c.peek(3)}\n\n" # peek() method puts "String Scanner peek form : #{c.peek(6)}\n\n" # peek() method puts "String Scanner peek form : #{c.peek(9)}\n\n"
Producción :
String Scanner peek form : Mon String Scanner peek form : Mon Se String Scanner peek form : Mon Sep 1
Ejemplo #2:
# Ruby code for StringScanner.peek() method # loading StringScanner require 'strscan' # declaring StringScanner c = StringScanner.new("hellogeeks") # peek() method puts "String Scanner peek form : #{c.peek(2)}\n\n" # peek() method puts "String Scanner peek form : #{c.peek(4)}\n\n" # peek() method puts "String Scanner peek form : #{c.peek(8)}\n\n"
Producción :
String Scanner peek form : he String Scanner peek form : hell String Scanner peek form : hellogee
Publicación traducida automáticamente
Artículo escrito por mayank5326 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA