Best way to find a substring in a string

后端 未结 7 1380
北荒
北荒 2020-12-11 16:32

I have a problem where I am trying to search for a substring in string. That substring may or may not be in the string.

str = \"hello how are you?\"
substr =         


        
7条回答
  •  盖世英雄少女心
    2020-12-11 17:08

    To my knowledge there's no "magic" way to search for substrings really fast, unless you're ready to build some kind of search metadata (think index) beforehand. Doing so will most likely waste more time than it saves you unless you search through the same string a lot.

    As the search pattern is simple, I would steer clear of regex.

提交回复
热议问题