Hi,

How to find out the repeating substrings in a string which is having maximum characters.
eg : abc abcd a abc abcd
Answer : abcd

Recommended Answers

All 3 Replies

Hi,

How to find out the repeating substrings in a string which is having maximum characters.
eg : abc abcd a abc abcd
Answer : abcd

I think I might know what you are asking, but I am not sure and thus it would only be a guess. Please phrase your question more clearly.

if I'm not mistaken, you want to declare a String, containing several substrings, separated by an espace. after this, you would like to find the longest of those substrings.

one option could be, storing the String in a StringBuffer, setting the space as a token, and check where the difference is the longest between two tokens, and comparing that with the first string (between begin of substring and first token) and the last one (between the last token and the end of the StringBuffer)

Hi,

How to find out the repeating substrings in a string which is having maximum characters.
eg : abc abcd a abc abcd
Answer : abcd

Suppose you have a variable of type string. Let's apply a string tokenizer on it (contained in java.util if i'm not mistaken), with the SPACE character as delimiter. Let's have for example a variable of type Linked List (also in java.util). Every time you obtain a new substring, you test whether that current substring is present in the list (linkedList.contains(currentToken)) then it's a repeating one. If it's not in the list, you put it in there.

Sorry, thought you were searching only for repeating substrings... I have missed the maximum length thing...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.