scanf(fstr)
public
Scans the current string. If a block is given, it functions exactly like block_scanf.
arr = "123 456".scanf("%d%d") # => [123, 456] require 'pp' "this 123 read that 456 other".scanf("%s%d%s") {|m| pp m} # ["this", 123, "read"] # ["that", 456, "other"] # => [["this", 123, "read"], ["that", 456, "other"]]
See Scanf for details on creating a format string.
You will need to require ‘scanf’ to use String#scanf