我有一個字符串數組(如示例所示)。我只想知道其中最常見的是什麼。最常見的字符串定義爲: - 如果蘋果ipod touch出現10次(比如說),而蘋果ipod出現8次,那麼我會說蘋果ipod touch是所有元素中的主要/普通字符串。查找一組字符串的相關程度
Apple iPod touch, 8GB (with FaceTime Camera and Retina Display)
Aple Ipod Clasic 80gb 6th Generation Black
iPod classic 160GB - Silver
Apple 8GB iPod Touch
Apple Ipod Touch 8gb 4th Generation Mc540ll/a 8 Gb Newest Model
Apple iPod touch Black 4th Generation 8GB Touch Screen Wi-Fi MP3
Apple 8GB iPod touch�
Apple 8GB iPod touch MC540LL/A
Apple MC540LL/A - 8GB iPod Touch w/ Camera (4th Gen) (Newest Model)
Apple iPod Touch - 8 GB - Electronics
Apple iPod 8GB 4th Generation Black Touch
Apple iPod touch 8GB 4th Gen (Refurbished)
Apple Ipod Touch Digital Player - Apple Ios 5
Apple Ipod Touch 8G - White (4Th Gen)
Apple MC540LL/A iPod Touch 8GB (4th Generation)
(refurbished) Apple Ipod Touch 8gb (4th Generation)
Apple Ipod Touch 8Gb 4Th Generation
iPod Touch 8GB (4th Gen)
Apple Ipod Touch 32G - White (4Th Gen)
Apple iPod touch 8GB (4th Gen), White
Apple iPod touch White 4th Generation 8GB Touch Screen Wi-Fi MP3
Apple 32GB Black 4th Generation iPod Touch - MC544LL/A
Apple 8GB iPod touch�
Apple iPod touch 8GB - White - Electronics
Apple MC544LL/A - 32GB iPod Touch w/ Camera (4th Gen) (Newest Model)
所以,任何人都可以建議我一些很好的算法來做到這一點?問題是我沒有任何標準/基準與之比較。我只需要比較它們之間的所有元素並找出最常見的元素。這必須在PHP或Javascript中實現。
希望我在我的問題中很清楚。請評論,如果我不清楚的地方。
所以你想要在最多的行中出現的子字符串(可能只有完整的字數)?因爲那會是'Apple'。或者你想要最長的子串出現在多行? – biziclop 2012-03-23 21:52:57
您正在尋找整行還是其中的一部分的字符串?另外,您的搜索是否區分大小寫? – 2012-03-23 21:53:36
字符串應該是最長的並且不區分大小寫 – 2012-03-23 21:54:39