How to check string contains special character in ruby

前端 未结 7 1886
我在风中等你
我在风中等你 2021-02-12 22:31

How to check whether a string contains special character in ruby. If I get regular expression also it is fine.

Please let me know

7条回答
  •  耶瑟儿~
    2021-02-12 23:16

    Use str.include?.

    Returns true if str contains the given string or character.

    "hello".include? "lo"   #=> true
    "hello".include? "ol"   #=> false
    "hello".include? ?h     #=> true
    

提交回复
热议问题