如何比较2个句子并得到不同单词的索引 [英] How do I Compare 2 sentences and get index of the different words

查看:46
本文介绍了如何比较2个句子并得到不同单词的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个令人满意的div



< div id =   editableDiv contenteditable =   true> 
嘿@twitter #awesome
< / div >





我将收集其html内容为$('#editableDiv')。 html()



此时收集的html内容(1):< b> hey< / b> < span style =color:blue> @ twitter< / span> #awesome





一段时间后收集的html内容(2):< b> hey< / b> < span style =color:blue> @ twitter< / span> #awesome #website



现在,想要计算(1)和(2)之间的差异并获得不同单词的索引。

按此,网站是(1)和(2)中唯一不同的单词,因此

其起始索引和结束索引必须类似(61) ,69)

解决方案

('#editableDiv')。html()



html内容收集于这次(1):< b> hey< / b> < span style =color:blue> @ twitter< / span> #awesome





一段时间后收集的html内容(2):< b> hey< / b> < span style =color:blue> @ twitter< / span> #awesome #website



现在,想要计算(1)和(2)之间的差异并获得不同单词的索引。

按此,网站是(1)和(2)中唯一不同的单词,因此

其起始索引和结束索引必须类似(61) ,69)


检查这个..

http:// jsfiddle .net / kAZwB / 3 / [ ^ ]

I have a contenteditable div

<div id="editableDiv" contenteditable="true">
    hey @twitter is #awesome
</div>



I will collect its html content as $('#editableDiv').html()

html content collected at this time (1): <b>hey</b> <span style="color:blue">@twitter</span> #awesome


html content collected after some time (2): <b>hey</b> <span style="color:blue">@twitter</span> #awesome #website

And now, would like to calculate the differences between (1) and (2) and get the index of different words.
As per this, website is the only word different in (1) and (2) and so
its starting index and ending index must be something like (61, 69)

解决方案

('#editableDiv').html()

html content collected at this time (1): <b>hey</b> <span style="color:blue">@twitter</span> #awesome


html content collected after some time (2): <b>hey</b> <span style="color:blue">@twitter</span> #awesome #website

And now, would like to calculate the differences between (1) and (2) and get the index of different words.
As per this, website is the only word different in (1) and (2) and so
its starting index and ending index must be something like (61, 69)


Check this..
http://jsfiddle.net/kAZwB/3/[^]


这篇关于如何比较2个句子并得到不同单词的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆