Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Beginner q
Message
From
31/07/2003 13:51:59
 
General information
Forum:
ASP.NET
Category:
Other
Title:
Miscellaneous
Thread ID:
00815425
Message ID:
00815525
Views:
10
I am an hour ahead of you on the C# learning curve, but I've found the best way to learn stuff is to try to answer questions, so here is my first attempt to answer a C# question.

I don't know what errors you got, but this code works and shows two different approaches
using System;

namespace ConsoleApplication4
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class Class1
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			string str1 = "";
			string str2 = "";
			string itMatches = "";
			string itMatchesCase = "";

			Console.Write("INPUT FIRST STRING : ");
			str1 = Console.ReadLine();  	
	
			Console.Write("INPUT SECOND STRING : ");
			str2 = Console.ReadLine();  	

			Console.WriteLine("First use String.Compare(str1,str2)");
					
			int compcaseval= String.Compare(str1,str2);

			if (compcaseval==0)
				itMatches=str1 + " matches " + str2+" with Case Sensitivity" ;
			else
				itMatches=str1 + " does not match " + str2+" with Case Sensitivity" ;

			Console.WriteLine("Compare function returns  {0} without 3rd param",compcaseval);
			Console.WriteLine(itMatches);



			Console.WriteLine("Use the Compare Function setting third param true");
			Console.WriteLine("Expression returns : {0}",String.Compare(str1,str2,true));

			int compval= String.Compare(str1,str2,true);

			if (compval==0)
				itMatches=str1 + " matches " + str2+" without Case Sensitivity" ;
			else
				itMatches=str1 + " does not match " + str2+" without Case Sensitivity" ;

			Console.WriteLine("Compare function returns  {0} with 3rd param true  ",compval);
			Console.WriteLine(itMatches);           

			Console.WriteLine("Using str1.CompareTo(str2) you get case sensitivity and it returns "+str1.CompareTo(str2));
	
			// Equals returns bool but Compare returns int

			Console.WriteLine("Use the Equals function");
            if (str1.Equals(str2))
				itMatchesCase=str1 + " matches " + str2 +" with Case Sensitivity";
			else
				itMatchesCase=str1 + " does not match " + str2 + " with Case Sensitivity";
			Console.WriteLine(itMatchesCase);

			Console.WriteLine("Now compare just using != ");

			if (str1 != str2)
			{
				Console.WriteLine("{0} does not match {1}",str1,str2);
			}
			else
				Console.WriteLine("{0} matches {1}",str1,str2);

			Console.Read();		
		}
	}
}
Perhaps someone who actually knows something about this will jump in and help us both < bg >



>hi all,
>i have been tryin to get going into c# for the last day or two in between continuing to develop in vfp. i am trying to get an if statement to work where a controls text value is compared to "" but cannot get it to work.
>any ideas very welcome, i know that this is a silly q but is bugging me and i have to say that i am finding the help quite cumbersome to use, ohh for the ease of use of vfp8!
>
>if (PatientTextBox.Text != "")
> nameNode.InnerText = PatientTextBox.Text;
>else
> nameNode.InnerText = "Mark";
>
>Cheers
>~M


Charles Hankey

Though a good deal is too strange to be believed, nothing is too strange to have happened.
- Thomas Hardy

Half the harm that is done in this world is due to people who want to feel important. They don't mean to do harm-- but the harm does not interest them. Or they do not see it, or they justify it because they are absorbed in the endless struggle to think well of themselves.

-- T. S. Eliot
Democracy is two wolves and a sheep voting on what to have for lunch.
Liberty is a well-armed sheep contesting the vote.
- Ben Franklin

Pardon him, Theodotus. He is a barbarian, and thinks that the customs of his tribe and island are the laws of nature.
Previous
Reply
Map
View

Click here to load this message in the networking platform