?
Solved

Help with sorting data in string variable in xml file using VB.NET

Posted on 2014-08-03
6
Medium Priority
?
268 Views
Last Modified: 2014-08-04
Hi,

How do you sort data separated by ";" in a dataelement? For example my xml file contains a CTRY data element with the following data <CTRY>BEL,FRA,CAN,USA,DEU</CTRY>. How do I loop through all the records and sort the data alphabetically? For example <CTRY>BEL,CAN,FRA,DEU,USA</CTRY>.

Thanks,

Victor
0
Comment
Question by:vcharles
  • 3
  • 3
6 Comments
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 40238579
string s = "BEL,FRA,CAN,USA,DEU";
            List<String> ls1 = s.Split(',').ToList();
            ls1.Sort();
ls1 is a list, sorted alphabetically, with the individual country abbreviations
0
 

Author Comment

by:vcharles
ID: 40238676
Thanks for the code, do you have the solution in VB.NET?
0
 
LVL 45

Accepted Solution

by:
AndyAinscow earned 2000 total points
ID: 40238694
After a little look into the help files (for the syntax for the split function):

        Dim s As String = "BEL,FRA,CAN,USA,DEU"
        Dim ls1 As List(Of String) = s.Split(New [Char]() {","c}).ToList
        ls1.Sort()
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:vcharles
ID: 40238786
Hi,

How would you load the xml file below and sort all the ctry data element?

<Root>
<Table1>
<Item>1</Item>
<Ctry>BEL,USA,CAN<Ctry>
</Table1>
<Table1>
<Item>2</Item>
<Ctry>BEL,USA,CAN<Ctry>
</Table1>
<Table1>
<Item>3</Item>
<Ctry>FRA,USA,CAN<Ctry>
</Table1>
<Table1>
<Item>4</Item>
<Ctry>USA,CAN,FRA,NLD<Ctry>
</Table1>
</Root>

Thanks,

V.
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 40238928
I'd close this question and ask a new question with that.  My comment addresses (and solves) how to sort the elements in the comma separated string you gave.

ps.  I'd also have another think about what is required - it isn't obvious what you want from the XML.
0
 

Author Closing Comment

by:vcharles
ID: 40238948
Thank You.
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2
Suggested Courses

850 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