|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hello, all
I was looking for an algorithm to find continuous repeats in a string. For an example, Input: MNMOPMOPKLABABABX Output: MN{2: MOP}KL{3: AB}X It is kind of like a compression algorithm. But it only cares about the continuous repeats. Both the string and the potential repeat cycle may be very long, so the algorithm should have a relatively high efficiency. Anybody know such an algorithm existing? Or some algorithms which can be refered? Any suggestion welcomed! Thanks ![]() |
|
#2
|
||||
|
||||
|
It's called RLE compression. It's the same compression used in BMP files. Shouldn't be too hard to find code for if you look around a bit. I think you basically:
For each character, search forward for the same character. Once you find the match, check the characters between to see if they match the characters following the matching character. Repeat again if pattern continues. Here's a snippet of code: http://www.chilkatsoft.com/ChilkatDx/ck_rle.htm
__________________
"Science is constructed of facts as a house is of stones. But a collection of facts is no more a science than a heap of stones is a house." - Henri Poincare Last edited by dog135 : May 19th, 2004 at 12:14 PM. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Software Design > Looking for a string algorithm |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|