Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 两个子字符串可以合并为一个吗?_Javascript - Fatal编程技术网

Javascript 两个子字符串可以合并为一个吗?

Javascript 两个子字符串可以合并为一个吗?,javascript,Javascript,在Google的diff_match_补丁中,我发现了以下代码: best_common = shorttext.substring(j - suffixLength, j) + shorttext.substring(j, j + prefixLength); 但这不等于: best_common = shorttext.substring(j - suffixLength, j + prefixLength); ? 如果您想在其自然栖息地中看到此代码,请查看源代码

在Google的diff_match_补丁中,我发现了以下代码:

best_common = shorttext.substring(j - suffixLength, j) +
            shorttext.substring(j, j + prefixLength);
但这不等于:

best_common = shorttext.substring(j - suffixLength, j + prefixLength);
?

如果您想在其自然栖息地中看到此代码,请查看源代码:


查找第673行和第674行。

是的,它们与
后缀长度
相同,
前缀长度
在您的情况下保证为非负。

对于大多数情况,它们是等效的。然而,有一个边缘情况需要考虑。 对于以下示例,我们假设
shorttext==“abcdefghijklmnopqrstuvxyz”

前缀长度
后缀长度
为负 设
j=12
前缀长度=-4
后缀长度=-5
。然后

shorttext.substring(j - suffixLength, j) + shorttext.substring(j, j + prefixLength)
// == "mnopq" + "jkl"
shorttext.substring(j - suffixLength, j + prefixLength)
// == "jklmnopq"

是的,有些人只是做一些长期的事情这应该是相同的,只有当
后缀长度
前缀长度
为负数时才是不同的。你能链接一些上下文的源代码吗?