Taark
Taark

Reputation: 11

How to get the difference in texts by words?

I want to use library https://github.com/sergi/go-diff

package main

import (
    "fmt"
    "github.com/sergi/go-diff/diffmatchpatch"
)

func main() {
    dmp := diffmatchpatch.New()
    text1 := "some text"
    text2 := "other text"
    diffs := dmp.DiffMain(text1, text2, true)
    fmt.Println(diffs)

}

output:

[{Delete s} {Equal o} {Delete m} {Insert th} {Equal e} {Insert r} {Equal  text}]

i wont:

[{Delete some}  {Insert other} {Equal  text}]

Is it possible?

P.S. Sorry for my English.

Upvotes: 0

Views: 684

Answers (1)

Kitsor
Kitsor

Reputation: 144

Check this

package main

import (
    "fmt"

    "github.com/sergi/go-diff/diffmatchpatch"
)

func main() {
    dmp := diffmatchpatch.New()
    text1 := "some text"
    text2 := "other text"

    diffs := dmp.DiffMain(text1, text2, true)
    fmt.Println(dmp.DiffCleanupSemantic(diffs))
}

Upvotes: 1

Related Questions