Re: String compare



On Mar 12, 4:20 pm, Muhs <shumy...@xxxxxxxxx> wrote:
Hi !!
i want to compare two strings and return the difference

For example, i have two strings,
string str1="then";
string str2="than";

it compared the two strings and returns 1, as only one character is
different (a and e).
Is there a function in c# that can do this??

I don't think so.

This is quite easy, so I suspect it is homework. You won't learn if
you get somebody else to write the code for you. If you have written
some code and are having trouble, then post it with a description of
the problem and we can probably help.

If it is not homework, then what is the application? (I can think of
a number of issues with the specification as it stands, and the
resolution will depend on the application.)
.



Relevant Pages

  • Re: A note on computing thugs and coding bums
    ... Here's my response including a bug fix. ... to make "modern strings" possible was designed and first implemented ... contents to strings, to compare them, and to duplicate them. ... while the Pike code will NEVER work...for international strings. ...
    (comp.programming)
  • Re: Ascan with a Substr
    ... the above suggestion: ... operator to compare the strings. ... code block you originally used was just right, ...
    (comp.lang.clipper)
  • Re: Ascan with a Substr
    ... The following solution work well ... operator to compare the strings. ... code block you originally used was just right, ...
    (comp.lang.clipper)
  • Re: almost equal strings
    ... Those are good for comparing words, or arbitrary strings, as Roedy asked, but he reveals that he actually wants to compare phrases. ... You might need a more refined scoring method, though - not all insertion, deletions or substitutions are of equal importance. ... Anyway, i don't think cljp is the place to ask about this - there is a huge body of knowlege about text processing which Roedy could tap into, and there must be a place to ask questions on it. ...
    (comp.lang.java.programmer)
  • Re: Fast and Safe C Strings: User friendly C macros to Declare and use C Strings.
    ... Explain how such strings will improve the speed of strchr. ... If comparison fails, compare value against "needle" ... And these of course are just buffer overflows waiting to happen anyways. ... comparison of _one_ character: 'a' is not equivalent to 'f', ...
    (comp.lang.c)