-8

如果第二个字符串存在于第一个字符串中,我想比较两个字符串并返回 true。

   @Test
   public bool compareStrings{
        String text1="hello world";
        String text2="hello but some xyz world and xzy bla bla";
        /* I want to check if text2 contains text1 */
   }
4

2 回答 2

2

尝试这样的事情: -

text2.toLowerCase().contains(text1.toLowerCase())
于 2013-01-22T17:37:12.903 回答
1

你想做:

if (text2.indexOf(text1) > -1)
{
  // text2 contains text1
}
于 2013-01-22T17:37:19.713 回答