Solved

Best way to sort 2 strings alphabetically

Posted on 2004-08-05
4
195 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: Ivo
Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

16 Experts available now in Live!

Get 1:1 Help Now