Does Ruby have a string.startswith(“abc”) built in method?

后端 未结 4 1132
轻奢々
轻奢々 2020-12-23 12:41

Does Ruby have a some_string.starts_with(\"abc\") method that\'s built in?

4条回答
  •  温柔的废话
    2020-12-23 13:22

    You can use String =~ Regex. It returns position of full regex match in string.

    irb> ("abc" =~ %r"abc") == 0
    => true
    irb> ("aabc" =~ %r"abc") == 0
    => false
    

提交回复
热议问题