[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
SolvedPrivate

Sorting with Punctuation - vb.net

Posted on 2014-08-08
3
Medium Priority
?
49 Views
Last Modified: 2016-02-17
I have an array list of names (Lastname, FirstName). Sort and Compare do not return the correct output.  Some of the names (first and last) have hyphens in them. Anyone know how to work around this?
0
Comment
Question by:mosemadl
3 Comments
 
LVL 27

Accepted Solution

by:
Sammy Ageil earned 2000 total points
ID: 40249922
Comparing and sorting are two different things, if you have encountered this issue https://connect.microsoft.com/VisualStudio/feedback/details/785931/string-compare-with-accents-on-framework-4-5-windows-8 then you can Try using the sort key to get an accurate compare,

Private Shared Function CompareStringUsingSortKey(left As String, right As String) As Integer
      Dim sk1 As SortKey = CultureInfo.InvariantCulture.CompareInfo.GetSortKey(left)
      Dim sk2 As SortKey = CultureInfo.InvariantCulture.CompareInfo.GetSortKey(right)
      Return SortKey.Compare(sk1, sk2)
End Function

For sorting, you can use linq
Dim sorted = things.[Select](Function(s) s.Split("-"C)).OrderBy(Function(x) Double.Parse(x(0))).ThenBy(Function(x) Double.Parse(x(1))).[Select](Function(x) [String].Join("-", x)).ToList()

Basically split and join
0
 
LVL 46

Expert Comment

by:aikimark
ID: 40250121
If the strings are "lastname, firstname" format, I don't see any problem sorting them.  How does the hyphen cause you problems?
0
 

Author Closing Comment

by:mosemadl
ID: 40253003
Thank you.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Loops Section Overview
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

873 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