Compare strings for equality with String::Equals : String « Data Type « Visual C++ .NET

Home
Visual C++ .NET
1.2D
2.Class
3.Collections
4.Data Type
5.Database ADO.net
6.Delegate
7.Development
8.File Directory
9.Function
10.Generics
11.GUI Form
12.Language Basics
13.Network
14.Reflection
15.Security
16.Statement
17.Structure
18.Thread
19.XML
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Visual C++ .NET » Data Type » String 
Compare strings for equality with String::Equals
 
#include "stdafx.h"
using namespace System;

int main()
{
   String^ str1 = "1";
   String^ str2 = "1";
   String^ str3 = str1;

   if (str1 == str2)
   {
      Console::WriteLine(" str1 == str2" );
   }
   if (str1 == str3)
   {
      Console::WriteLine(" str1 == str3" );
   }
   if (str1->Equals(str2))
   {
      Console::WriteLine(" str1 Equals str2" );
   }
   if (str1->Equals(str3))
   {
      Console::WriteLine(" str1 Equals str3");
   }

   if (String::ReferenceEquals(str1, str2))
   {
      Console::WriteLine(" str1 ReferenceEquals str2");
   }
   if (String::ReferenceEquals(str1, str3))
   {
      Console::WriteLine(" str1 ReferenceEquals str3");
   }
}

   
  
Related examples in the same category
1.String Literals
2.Create a String
3.Create some strings
4.Reverse a string
5.Output a string
6.Insert into a string
7.Remove text from strings
8.Create a copy, then concatenate new text
9.Replace stuff in a concatenated string
10.Compare two strings with String::Compare
11.Use static method String::Compare to compare two strings
12.Compare strings for equality with ==
13.Compare strings for equality with String::ReferenceEquals
14.Using string for each loop to output chars
15.String operator plus
16.Convert back to a String using the String constructor that takes a Unicode character array.
17.Convert String to char array
18.Convert String to char pointer
19.Convert text read from stdin to uppercase and write to stdout
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.