Link to home
Start Free TrialLog in
Avatar of nightshadz
nightshadzFlag 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!
SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Doesn't handle the 2nd sample Norie (PostalAddress#DeliveryAddress#AddressLine1)
Avatar of Norie
Norie

Oops, didn't notice that 2nd #.

I'll need to rethink.
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