الثلاثاء، 24 ديسمبر 2013

Detect if a string consists of a substring of a string

You can split the strings into two arrays

a = "sun is clear".splitb = "sun cloud rain".split

and compute the intersection

a & b# => ["sun"] (a & b).empty?# => false

If the intersection is not empty, then they share pieces. Otherwise, you can also compute the difference of a - b

(a - b).size == a.size# => false

View the original article here

ليست هناك تعليقات:

إرسال تعليق