?
Solved

Help with entering "-" multiple location in NSC data element

Posted on 2015-01-30
9
Medium Priority
?
80 Views
Last Modified: 2015-02-06
Hi,

How do I convert data in my NSC data element from xxxxxxxxxxxxx to xxxx-xx-xxx-xxxx using VB.NET?

Thanks,

Victor
0
Comment
Question by:vcharles
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 40580956
Hi Victor;

What exactly is NSC data element? What is the data type of the field you are trying to re-format?
0
 

Author Comment

by:vcharles
ID: 40580991
Hi Fernando,

I would like to convert file A to file B, for example if file A contains:

<Root>
<Table>
<ID>1</ID>>
<Item></Item>
<NSC>1111111111111<NSC>
</Table>
<Table>
<ID>2</ID>>
<Item></Item>
<NSC>2222222222222<NSC>
</Table>
<Table>
<ID>3</ID>>
<Item></Item>
<NSC>3333333333333<NSC>
</Table>
</Root>

How do I obtain file B as shown below:

<Root>
<Table>
<ID>1</ID>>
<Item></Item>
<NSC>1111-11-111-1111<NSC>
</Table>
<Table>
<ID>2</ID>>
<Item></Item>
<NSC>2222-22-222-2222<NSC>
</Table>
<Table>
<ID>3</ID>>
<Item></Item>
<NSC>3333-33-333-3333<NSC>
</Table>
</Root>

Victor
0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 40581020
Hi Victor;

The following code snippet will reformat the NSC node as per example.

'' Load XML document into memory
Dim xdoc = XDocument.Load("C:\Working Directory\nscData.xml")                                               

// Get a reference to all the NSC nodes in the document                                                                                                            
Dim result = (From n In xdoc.Descendants("NSC")                                                             
              Select n).ToList()                                                                            

'' Reformat the Text in NSC node                                                                                                             
result.ForEach(Sub(nsc) nsc.Value = Regex.Replace(nsc.Value, "(\d{4})(\d{2})(\d{3})(\d{4})", "$1-$2-$3-$4"))

xdoc.Save("C:\Working Directory\nscData-Reformatted.xml")

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:vcharles
ID: 40581031
Thank You.
0
 

Author Comment

by:vcharles
ID: 40581032
Thank You.
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 40581035
You will need this import for the regular expression.

Imports System.Text.RegularExpressions
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 40592859
Hi Victor, how are you doing with this question?
0
 

Author Comment

by:vcharles
ID: 40593189
Hi Fernando,

I am sorry for the late reply. The codes worked.

Thank You.
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 40593670
Not a problem Victor, glad to help.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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 …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

771 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