Ruby: How to find out if a character is a letter or a digit?

前端 未结 3 731
伪装坚强ぢ
伪装坚强ぢ 2021-02-05 05:15

I just started tinkering with Ruby earlier this week and I\'ve run into something that I don\'t quite know how to code. I\'m converting a scanner that was written in Java into R

3条回答
  •  轮回少年
    2021-02-05 05:28

    The simplest way would be to use a Regular Expression:

    def numeric?(lookAhead)
      lookAhead =~ /[0-9]/
    end
    
    def letter?(lookAhead)
      lookAhead =~ /[A-Za-z]/
    end
    

提交回复
热议问题