Avatar of nightshadz
nightshadz
Flag for United States of America asked on

C# LINQ

Is there a solution using LINQ to build a new string based on the following criteria?

Concatenate each uppercase letter to the left of each # , then include everything after the last #. A few examples:

Name#FormOfAddress becomes NFORMOFADDRESS
PostalAddress#DeliveryAddress#AddressLine1 becomes PADAADDRESSLINE1

Thanks!
C#LINQ Query

Avatar of undefined
Last Comment
Norie

8/22/2022 - Mon
SOLUTION
Kyle Abrahams

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Norie

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Kyle Abrahams

Doesn't handle the 2nd sample Norie (PostalAddress#DeliveryAddress#AddressLine1)
Norie

Oops, didn't notice that 2nd #.

I'll need to rethink.
Norie

This works for the other sample and some others I tried.
            string aString = "PostalAddress#DeliveryAddress#AddressLine1";
            string result = "";

            IEnumerable<char> stringQuery =
              from ch in aString.Substring(0,aString.LastIndexOf('#', aString.Length-2)+1) 
              where Char.IsUpper(ch)
              select ch;

            foreach (char c in stringQuery)
                result += c;

            result += aString.Substring(aString.LastIndexOf('#', aString.Length - 2) + 1).ToUpper();

Open in new window

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck