Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

StringScanner#getch

getch

Scans one character and returns it. This method is multibyte character sensitive.

Example
s = StringScanner.new("ab")
s.getch           # => "a"
s.getch           # => "b"
s.getch           # => nil

s = StringScanner.new("\244\242".force_encoding("euc-jp"))
s.getch           # => "\x{A4A2}"   # Japanese hira-kana "A" in EUC-JP
s.getch           # => nil
See also #getbyte #initialize_copy #get_byte #inspect also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0