-2

重複の可能性:
指定された文字列の最も長く繰り返される部分文字列を見つける方法

文字列の最も長く繰り返された部分文字列を見つけることを想定しています。

    /**
This method will find the longest substring of a given string.
String given here is reassuring. 

 */
public String longestRepeatedSubstring()
{
    String longestRepeatedSubstring = "";
    for (int i = 0; i<text.length(); i++ )
    {
        String one = text.substring(0,i); 

        for(int o = 0; o<text.length();o++)
        {
            Sting two = text.substring(0,o);
            if(one.equals(two))
            {
                longestRepeatedSubstring = one;
            }

        }

    }
    return longestRepeatedSubstring; 
}
4

1 に答える 1

0

正規表現を使用したほうがよいでしょう。ここにあります:

/(?=((.+)(?:.*?\2)+))/s
于 2012-11-03T19:07:35.177 に答える