?
Solved

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

Posted on 2015-01-30
9
Medium Priority
?
92 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 64

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 64

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
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 

Author Comment

by:vcharles
ID: 40581031
Thank You.
0
 

Author Comment

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

Expert Comment

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

Imports System.Text.RegularExpressions
0
 
LVL 64

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 64

Expert Comment

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

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month13 days, 14 hours left to enroll

809 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