objective-c – 如何识别两个字符串之间的变化增量?
发布时间:2020-12-16 07:29:20 所属栏目:百科 来源:网络整理
导读:我必须实现一个算法,该算法将两个字符串作为输入,并返回一个包含子字符串变化范围的数组. 比方说,范围定义为 typedef struct _NSRange { NSUInteger location; // Where the affected substring begins NSUInteger length; // How long the affected substri
我必须实现一个算法,该算法将两个字符串作为输入,并返回一个包含子字符串变化范围的数组.
比方说,范围定义为 typedef struct _NSRange { NSUInteger location; // Where the affected substring begins NSUInteger length; // How long the affected substring is } NSRange; 例: string1 = "My cat sometimes likes to eat fish."; string 2 = "My cat always likes to drink fresh water,and eat fish."; 变化是: > {7,9}“有时”改为{7,6}“总是” 我需要一个包含按变化分组的子串的数组.在这个例子中,它看起来像这样: >“我的猫” 目标是突出显示现有字符串中的这些更改,我必须根据更改将该字符串拆分为子字符串. 在重新发明轮子之前 – 公共领域是否有解决方案? 解决方法
您基本上尝试实现相当于
diff.如维基百科页面中所述,它使用
longest common subsequence problem算法.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |