Help:find repeating substrings in sting

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2008
Posts: 1
Reputation: RituNimitNayal is an unknown quantity at this point 
Solved Threads: 0
RituNimitNayal RituNimitNayal is offline Offline
Newbie Poster

Help:find repeating substrings in sting

 
0
  #1
Aug 25th, 2008
Hi,

How to find out the repeating substrings in a string which is having maximum characters.
eg : abc abcd a abc abcd
Answer : abcd
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,844
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 503
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Help:find repeating substrings in sting

 
0
  #2
Aug 25th, 2008
Originally Posted by RituNimitNayal View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: Help:find repeating substrings in sting

 
0
  #3
Aug 25th, 2008
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)
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 59
Reputation: Chaster is an unknown quantity at this point 
Solved Threads: 3
Chaster Chaster is offline Offline
Junior Poster in Training

Re: Help:find repeating substrings in sting

 
0
  #4
Aug 25th, 2008
Originally Posted by RituNimitNayal View Post
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...
Last edited by Chaster; Aug 25th, 2008 at 6:10 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum


Views: 1687 | Replies: 3
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC