We help IT Professionals succeed at work.

Help with removing duplicates in string using VB.NET

232 Views
Last Modified: 2014-08-01
Hi,

I have an xml file which contains a data element with string of duplicate data.For example<CTRY>BEL,BEL,GRC,GRC,USA<CTRY>. How do I remove the duplicate data?

For example:

<Root>
<Table>
<Id>1</id>
<ctry>BEL,BEL,GRC,GRC,USA<CTRY</ctry>
<Item>BMW</item>
</Table>
<Table>
<Id>1</id>
<ctry>BEL,BEL,GRC,GRC,USA,USA<CTRY</ctry>
<Item>BMW</item>
</Table>
<Table>
<Id>1</id>
<ctry>BEL,DEU,GRC,BEL,USA<CTRY</ctry>
<Item>BMW</item>
</Table>
</Root>

Thanks,

Victor
Comment
Watch Question

Commented:
XmlDoc.DocumentElement("ctry").InnerText =
string.Join(",", XmlDoc.DocumentElement("ctry").InnerText.Split(',').Distinct().ToArray());

Commented:
not sure how you are parsing the xml but the idea is as ollows
dim duplicateString as string
duplicateString= "BEL,BEL,GRC,GRC,USA";

Dim cleanString as string = string.Join(",", duplicateString.Split(',').Distinct().ToArray())

Author

Commented:
H

Once i load the file using xmldocument how do i use your code and save the changes?

Thanks.
Retired
CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks, I will try it and get back to you.

victor

Author

Commented:
Thank You.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.