Help with passing values to dataelement based on partial string

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

vcharlesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vcharlesAuthor Commented:
Hi,

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

Victor
0
Fernando SotoRetiredCommented:
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
vcharlesAuthor 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
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Fernando SotoRetiredCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vcharlesAuthor Commented:
Thank You.
0
Fernando SotoRetiredCommented:
No problem Victor, glad to help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.