I need to manipulate large strings in Java (deleting and adding the deleted
chars again, moving chars around), but still want to remember the
original position offsets. E.g. the word “computer” starts at offset
133 in the original text and is then moved to position 244, I still
want the info that it was originally at position 133.
The most ugly (and resource hungry) solution would be to store for
every character its original position plus it’s position change. There
are surely better solutions, but also more complex ones.
Are there any good text manipulation libraries that have a solution to
my problem? I don’t want to reinvent the wheel.
Regards,
Kai
How large are these strings ? Given the quantities of memory available today, brute force may be the way to go.
You talk about moving words, but storing character positions. Why not store word positions, and a history per instance of word. Note that you could be clever and make use of the flyweight pattern to save having multiple instances of these objects until you require. i.e. your ‘string’ object holds one ‘computer’ word object, but records that that word occurs at position 133, 245, 667 etc. (plus history as and when you need it)