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

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
vcharlesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
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
vcharlesAuthor Commented:
Thanks for the code, do you have the solution in VB.NET?
0
AndyAinscowFreelance programmer / ConsultantCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

vcharlesAuthor Commented:
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
AndyAinscowFreelance programmer / ConsultantCommented:
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
vcharlesAuthor Commented:
Thank You.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.