Javascript比较字符串并得出结尾差异 [英] Javascript compare strings and get end difference
本文介绍了Javascript比较字符串并得出结尾差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个字符串. 字符串-答:快速的棕色狐狸" 字符串B:那只敏捷的棕色狐狸跳过了那只懒狗."
I have two strings. String A: "The quick brown fox" String B: "The quick brown fox jumps over the lazy dog."
字符串B将始终包含字符串A的逐字记录.永远不会有快速的黑狐狸"或快速而快速的棕色狐狸".
String B will always contain string A verbatim. There will never be a "quick black fox" or a "quick and speedy brown fox".
如何获得差异跳过懒狗"的字符串C"?
How do a get a "String C" of the difference "jumps over the lazy dog."?
推荐答案
const A = "The quick brown fox"
const B = "The quick brown fox jumps over the lazy dog."
const diff = (diffMe, diffBy) => diffMe.split(diffBy).join('')
const C = diff(B, A)
console.log(C) // jumps over the lazy dog.
这篇关于Javascript比较字符串并得出结尾差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文