Solved

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

Posted on 2015-01-30
9
55 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 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

16 Experts available now in Live!

Get 1:1 Help Now