Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How Do You Compare Strings In C#?
Message
From
07/01/2005 12:08:29
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
00975060
Message ID:
00975158
Views:
16
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform