Finding the difference between strings in Ruby

前端 未结 5 989
长发绾君心
长发绾君心 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:21

    easy solution:

     def compare(a, b)
       diff = a.split(', ') - b.split(', ')
       if diff === [] // a and b are the same
         true
       else
         diff
       end
     end
    

    of course this only works if your strings contain comma-separated values, but this can be adjusted to your situation.

提交回复
热议问题