Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
1.how to compare words in a string and highlight the differences added text deleted text in c#.



Looking for like this:
diffString(

"The red brown fox jumped over.",

"The brown spotted fox leaped over")
output:
The red brown spotted fox jumped leaped over

What I have tried:

2.used code match patch but it is comparing on character basis.
3.Used diffplex but result is only the differences and it is in array.
Posted
Updated 27-Sep-22 19:27pm
Comments
Sandeep Mewara 28-Sep-22 1:23am    
One of the ways: You can achieve this by using regular expression and stringcollection. You would need to check whether first stringcollection words are contained in another or not.

1 solution

Think about how you would do this in the real world: you would break the string into individual words and then compare them.
So start there: break the string into words first (using a Regex or String.Split) and go from there.

If you have code that works character by character on on an array, then the algorithm is the same - you just change the comparison to use strings from an array of strings instead of of characters.

But since we have no access to the code you have written so far we can't be at all specific!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900