Finding the difference between strings in Ruby

前端 未结 5 979
长发绾君心
长发绾君心 2021-02-07 19:00

I need to take two strings, compare them, and print the difference between them.

So say I have:

teamOne = \"Billy, Frankie, Stevie, John\"
teamTwo = \"Bi         


        
5条回答
  •  孤街浪徒
    2021-02-07 19:41

    If the real string you are comparing are similar to the strings you provided, then this should work:

    teamOneArr = teamOne.split(", ")
    => ["Billy", "Frankie", Stevie", "John"]
    teamTwoArr = teamTwo.split(", ")
    => ["Billy", "Frankie", Stevie"]
    teamOneArr - teamTwoArr
    => ["John"]
    

提交回复
热议问题