Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How Do You Compare Strings In C#?
Message
De
07/01/2005 12:08:29
 
 
À
07/01/2005 09:14:26
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
00975060
Message ID:
00975158
Vues:
17
Kevin,

If I recall correctly, I had given you sorter compare code for dates, because that's what you were trying to sort at the time. Off the top of my head, I don't remember why it didn't work for you, but anyway, comparing strings is slightly different, you need to use the string.Compare(s1, s2) method. Your compare method for your sort should look something like this for a string comparison (this code is for a ListViewItem compare, you'll need to tweak it just a bit for your ArrayList):
public override int Compare(object x, object y)
{
	ListViewItem row1, row2;
	string s1, s2;
	row1 = (ListViewItem)x;
	row2 = (ListViewItem)y;

	s1 = row1.SubItems[this.ColumnIndex].Text;
	s2 = row2.SubItems[this.ColumnIndex].Text;

	return string.Compare(s1, s2);
}
~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform