Solved

Best way to sort 2 strings alphabetically

Posted on 2004-08-05
4
197 Views
Last Modified: 2010-04-15
What's the best way to sort 2 string alphabetically?
0
Comment
Question by:natejacobs
  • 2
4 Comments
 
LVL 9

Expert Comment

by:noulouk
ID: 11726610
Hi natejacobs,

I often use something like this:

int result = string.Compare(str1,str2,true);
 in which str1 and str2 are the strings you wish to compare and true means ignore casing (false means make a casesensitive comparison).

Test the result of the Compare function. If result = 0 then the strings are equal. If the result is a negative number, then str1 comes before str2 alphabetically. If the result is a positive number, then str1 comes after str2 alphabetically

Hope this helps.

0
 
LVL 4

Expert Comment

by:NTAC
ID: 11727195
What are you trying to do?
0
 
LVL 3

Author Comment

by:natejacobs
ID: 11729148
I'm sorting a list view when a column is clicked.
0
 
LVL 9

Accepted Solution

by:
noulouk earned 250 total points
ID: 11731186
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now