How to realize a diff function?

后端 未结 5 2026
耶瑟儿~
耶瑟儿~ 2021-02-04 22:49

How can I implement a diff function, such as Stack Overflow\'s question revision history?

5条回答
  •  孤城傲影
    2021-02-04 23:11

    You have here a javascript example of the implementation of a diff algorithm.

    Based on:

    P. Heckel, A technique for isolating differences between files Comm. ACM, 21, (4), 264--268 (1978).

    The implementation, itself, has two functions, one of which is recommended for use:

    diffString( String oldFile, String newFile )
    

    This method takes two strings and calculates the differences in each. The final result is the 'newFile' marked up with HTML (to signify both deletions from the oldFile and additions to the newFile).

提交回复
热议问题