2

I'm doing some work and I've come across an issue--I have two strings, which may or may not be different from one another. They started off the as the same string originally, and then were separately modified. How do I reconcile or join these two strings again?

Do I need to keep track of exactly which modifications were made to each string, and then apply each of those modifications to the original string? I'm not sure how to do that--each string is being modified in a textarea.

user207421
  • 305,947
  • 44
  • 307
  • 483
Elliot Bonneville
  • 51,872
  • 23
  • 96
  • 123
  • 1
    Could you explain what you mean by reconcile? A practical example including input, changes and expected output would be most welcome. – Tibos Jan 12 '14 at 21:49
  • To add to what Tibos said, if the original string was "Apples are red", and the two modified strings were "Roses are red" and "Bananas are yellow", what should the output be? – bfavaretto Jan 12 '14 at 22:02

1 Answers1

2

I think you're looking for a text merging algorithm, as is used by source control management tools such as git or svn to merge source code that has been edited simultaneously by two developers.

A situation something like this:

enter image description here

If that is the case, you can have a look at these questions:

Keywords are text comparison, merging, merge conflicts, three-way merge algorithm, diff, and diff3.


Another possibility that became popular lately, is real-time collaboration where users can simultaneously edit the same document, as was the core feature of Google Wave, which is now part of Google Docs.

The term to look for there, is Operational Transformation. There are a plenty of youtube videos with Google engineers illustrating the principles.

Related are share.js, and Mozilla's together.js.

And a last one: Real-time Collaborative Editing with Web Sockets, Node.js & Redis

Community
  • 1
  • 1
wkampmann
  • 1,405
  • 12
  • 13