nightshadz
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#DeliveryAddr ess#Addres sLine1 becomes PADAADDRESSLINE1
Thanks!
Concatenate each uppercase letter to the left of each # , then include everything after the last #. A few examples:
Name#FormOfAddress becomes NFORMOFADDRESS
PostalAddress#DeliveryAddr
Thanks!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Doesn't handle the 2nd sample Norie (PostalAddress#DeliveryAdd ress#Addre ssLine1)
Oops, didn't notice that 2nd #.
I'll need to rethink.
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();