String manipulation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • napstar
    New Member
    • Nov 2006
    • 55

    #1

    String manipulation

    How do u find out if 2 strings are the same in c#?
  • mwalts
    New Member
    • May 2007
    • 38

    #2
    Originally posted by napstar
    How do u find out if 2 strings are the same in c#?
    Do you mean have the same contents, or the same reference?

    Contents:
    string hello1 = "Hello";
    string hello2 = "Hello";

    Console.WriteLi ne((hello1==hel lo2) + "");
    should give you true (or 1, whatever, can't remember what .net gives us again)
    but
    Console.WriteLi ne(object.Refer enceEquals(hell o1,hello2) + "");
    may give you false because it checks to see if hello1 and hello2 are referencing the same object in memory.

    I think in this case both return true because of the way the compiler deals with constant strings... but it's easy to image a situation where it wouldn't

    -mwalts

    Comment

    • srics
      New Member
      • Mar 2007
      • 8

      #3
      You could use String.Equals also. It determines whether two strings are having the same value.

      Comment

      Working...