What's the fastest way to check if a word from one string is in another string?

后端 未结 8 926
故里飘歌
故里飘歌 2020-12-30 12:56

I have a string of words; let\'s call them bad:

bad = \"foo bar baz\"

I can keep this string as a whitespace separated string,

8条回答
  •  情话喂你
    2020-12-30 13:21

    bad = "foo bar baz"

    => "foo bar baz"

    str = "This is my first foo string"

    => "This is my first foo string"

    (str.split(' ') - bad.split(' ')).join(' ')

    => "This is my first string"

提交回复
热议问题