Strings issue...
-
Hi everyone! I'm working on a project and i need to do what follows: i have an array of strings,example: house3 house2 green23 green.5 H6 H01 G19 G78 ..and so on. I have to extract only the recurrent strings: house,green,H,G. Any idea about it? (the language is java but doesn't matter, i just need the idea!) Thanks in advance, Enrico.
Program your life ^^
-
Hi everyone! I'm working on a project and i need to do what follows: i have an array of strings,example: house3 house2 green23 green.5 H6 H01 G19 G78 ..and so on. I have to extract only the recurrent strings: house,green,H,G. Any idea about it? (the language is java but doesn't matter, i just need the idea!) Thanks in advance, Enrico.
Program your life ^^
The following should give you some ideas: http://en.wikipedia.org/wiki/Patricia_tree[^]
...cmk The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying. - John Carmack
-
Hi everyone! I'm working on a project and i need to do what follows: i have an array of strings,example: house3 house2 green23 green.5 H6 H01 G19 G78 ..and so on. I have to extract only the recurrent strings: house,green,H,G. Any idea about it? (the language is java but doesn't matter, i just need the idea!) Thanks in advance, Enrico.
Program your life ^^
What are you gonna do exactly ? Do you want to identify the strings that contain
house,green,H,G
? -
What are you gonna do exactly ? Do you want to identify the strings that contain
house,green,H,G
? -
Hi everyone! I'm working on a project and i need to do what follows: i have an array of strings,example: house3 house2 green23 green.5 H6 H01 G19 G78 ..and so on. I have to extract only the recurrent strings: house,green,H,G. Any idea about it? (the language is java but doesn't matter, i just need the idea!) Thanks in advance, Enrico.
Program your life ^^
Some of the problem parameters aren't clear: Do the recurrent strings always start at the beginning of the line? Do you just ignore non-letters (numbers and punctuation)? If the answer to both of these questions is yes, you can do this:
1. For each line
2. Extract the string of just the letters from the beginning of the line.
3. See if this string is in a hash table. If so, it's a recurrent string.
4. Else insert this string into the hash table.If the strings don't always start at the beginning of the line, you have to do multiple insertions for each string: the whole string, the substring starting at the 2nd letter, 3rd letter, etc...
-
Hi everyone! I'm working on a project and i need to do what follows: i have an array of strings,example: house3 house2 green23 green.5 H6 H01 G19 G78 ..and so on. I have to extract only the recurrent strings: house,green,H,G. Any idea about it? (the language is java but doesn't matter, i just need the idea!) Thanks in advance, Enrico.
Program your life ^^
You need to look at using a data structure like a Trie[^], or as was already pointed out Patrcia Trie[^]. The Wikipedia articles should give you enough information to get started on an actual implementation.
Scott Dorman
Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]
Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai