Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How Do You Compare Strings In C#?
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
00975060
Message ID:
00975150
Vues:
13
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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform