Solved

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

Posted on 2015-01-30
9
50 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
  • 5
  • 4
9 Comments
 
LVL 62

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 62

Accepted Solution

by:
Fernando Soto earned 500 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
 

Author Comment

by:vcharles
ID: 40581031
Thank You.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

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

Expert Comment

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

Imports System.Text.RegularExpressions
0
 
LVL 62

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 62

Expert Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now