We help IT Professionals succeed at work.

Help with passing values to dataelement based on partial string

168 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

Comment
Watch Question

Author

Commented:
Hi,

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

Victor
Fernando SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
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.

Author

Commented:
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
Retired
CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thank You.
Fernando SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
No problem Victor, glad to help.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.