Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How Do You Compare Strings In C#?
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
00975060
Message ID:
00975150
Views:
14
Kevin,

You can use == to compare strings in C# like this:
string myS1 = "20050107";
string myS2 = "20050207";

if (myS1 == myS2)
	MessageBox.Show("Strings are equal");
else
	MessageBox.Show("strings are not equal");
I guess it doesn't really make sense to check if a sring is less or greater than another string.
If you have a specific senario where comparing strings are usefull please post and I can take a look at it.

Einar


>>You have the right idea, but the keyword int is equal to System.Int32 and you convert it using Conver.ToInt16 and the max value for Int16 is 32767. Use Conver.ToInt32 instead:
>
>Thanks, both.
>
>Converting to an integer happens to work in this scenario, because both character strings are numeric.
>
>However, what if either string contained letters. How would they be compared in C#?
>
>TIA, Kevin
Semper ubi sub ubi.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform