Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compare strings and get end difference

I have two strings.
String A: "The quick brown fox"
String B: "The quick brown fox jumps over the lazy dog."

String B will always contain string A verbatim. There will never be a "quick black fox" or a "quick and speedy brown fox".

How do I get a "String C" of the difference "jumps over the lazy dog."?

like image 451
Ian McCullough Avatar asked Nov 05 '11 23:11

Ian McCullough


People also ask

How do you find the difference between two strings?

To find the difference between 2 Strings you can use the StringUtils class and the difference method. It compares the two Strings, and returns the portion where they differ.

What happens when you compare strings?

In String, the == operator is used to comparing the reference of the given strings, depending on if they are referring to the same objects. When you compare two strings using == operator, it will return true if the string variables are pointing toward the same java object. Otherwise, it will return false .

How do I compare two strings in TypeScript if condition?

Use the strict equality operator (===) to check if two strings are equal in TypeScript, e.g. if (str1 === str2) {} . The strict equality operator returns true if the strings are equal, otherwise false is returned.

What does string comparison mean?

string= compares two strings and is true if they are the same (corresponding characters are identical) but is false if they are not. The function equal calls string= if applied to two strings. The keyword arguments :start1 and :start2 are the places in the strings to start the comparison.


1 Answers

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.
like image 158
Mateja Petrovic Avatar answered Oct 08 '22 19:10

Mateja Petrovic