[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Help with passing values to dataelement based on partial string

Posted on 2014-08-01
6
Medium Priority
?
144 Views
Last Modified: 2014-08-02
Hi,

How d I modify the line below to look for part of AGD4, for example AGD4 contains data in the following format (XXXX-XX-XXXX) and I need to look for the mIddle value (-XX-) instead of the entire value of AGD4.


Group n By n.Element("AGD4").Value.substring (??)  Into agd4Group = Group

  '' Load the XML document to be summerized into memory
        Dim xdoc As XDocument = XDocument.Load(Application.StartupPath + "\AOP5.xml")

        '' Group the TableA nodes by AGD4 then get a string containing all the Country values order the Country values
        '' and return the groupings and summary string so that it can be inserted into the XML                                                                                                                      
        Dim results = (From n In xdoc.Descendants("AOP5C") Where n.Element("AGD4").Value <> "NA"
                       Group n By n.Element("AGD4").Value Into agd4Group = Group
                       Let sum = agd4Group.Select(Function(g) g.Element("COUNTRY").Value).OrderBy(Function(g) g).ToArray() _
                       From g In agd4Group _
                       Let summary = String.Join(",", sum) _
                       Select g, summary).ToList()

        '' Update the Summary node with the value of the summary string.                                                                                                                      
        results.ForEach(Sub(m) m.g.Element("CANMN").Value = m.summary)
        '' Save the document.                                                                                                                      
        xdoc.Save(Application.StartupPath + "\AOP5.xml")

Open in new window

0
Comment
Question by:vcharles
  • 3
  • 3
6 Comments
 

Author Comment

by:vcharles
ID: 40235577
Hi,

How do I include Substring(AGD4, 5, 3) in Group n By n.Element("AGD4").Value.substring (??)  Into agd4Group = Group?

Victor
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 40235600
Hi Victor;

Have you tried it this way?

Group n By n.Element("AGD4").Value.SubString(5, 2)  Into agd4Group = Group

Which will make the grouping the two middle characters, YY, in the pattern XXXX-YY-XXXX.
0
 

Author Comment

by:vcharles
ID: 40235663
Hi,

I tied it but received error message

Range variable name can  be inferred only from a simple or qualified name with no arguments.

Thanks,

Victor
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 64

Accepted Solution

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

Because the grouping value is not a simple variable but an expression we need to give it a name.

Group n By Key = n.Element("AGD4").Value.SubString(5, 2)  Into agd4Group = Group
0
 

Author Closing Comment

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

Expert Comment

by:Fernando Soto
ID: 40236043
No problem Victor, glad to help.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month20 days, 12 hours left to enroll

865 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