C
C#8mo ago
kenan (2)

❔ How can I diff 2 strings?

How can I find the difference between two strings (added/removed/modified characters/words)
14 Replies
phaseshift
phaseshift8mo ago
use git
Stan
Stan8mo ago
lel
kenan (2)
kenan (2)8mo ago
lol, but seriously, I'd like to do it in C#
Stan
Stan8mo ago
depends how accurate you want it, its gonna get a bit complex
phaseshift
phaseshift8mo ago
it's non-trivial if youre diffing e.g. multiple words, paragraphs
kenan (2)
kenan (2)8mo ago
Doesn't have to be accurate, just good enough to be able to recognize modified characters from one another. I tried writing my own algorithm for this and it turned out horrible so I'm asking if there are better solutions
phaseshift
phaseshift8mo ago
yeah, libgit
Stan
Stan8mo ago
honestly yeah, if theres a library for it, save yourself the trouble xD unless its like a code exercise kinda thing
kenan (2)
kenan (2)8mo ago
I've also found DiffPlex, is it any good?
Stan
Stan8mo ago
rule of thumb, go by most stars or downloads
kenan (2)
kenan (2)8mo ago
It has a decent amount of stars
No description
Stan
Stan8mo ago
read the docs, does it look usable enough for you?
Bailey
Bailey8mo ago
The best advice is use a library, However if it is to learn, the following is a start. However keep in mind, if there is a word added, then it wont work and with libraries there ie an algorithm which solve this. var unmoddifiedSentance = "th1s 1s just an example how to start"; var moddifiedSentance = "this is just a example how to start"; List<string> unmoddified = unmoddifiedSentance.Split(' ').ToList(); List<string> moddified = moddifiedSentance.Split(' ').ToList(); for (int i = 0; i < unmoddified.Count; i++) if (unmoddified[i] != moddified[i]) Console.WriteLine($"moddified word was: {unmoddified[i]} is {moddified[i]} "); // when you know the word is different you van search for the char Console.ReadLine( );
Accord
Accord8mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts