I'm having a string like "a.b.c.d.e".
If I want to get an array like "a.b.c.d.e", "b.c.d.e", "c.d.e", "d.e", "e" in C#. What's the simplest approach?
Something like this will do:
var stringParts = input.Split('.');
var result = Enumerable.Range(0, stringParts.Length)
.Select(i => string.Join(".", stringParts.Skip(i)));
But like I said in my comment, please show the code you came up with and why you want to make it a one-liner, which usually doesn't serve any benefit. This isn't codegolf.
If you really do it with one statement, you can try this:
var str = "a.b.c.d.e";
var parts = str.Split('.')
.Select((x,idx) => new { idx })
.Select(p => string.Join(".",
str.Split('.').Skip(p.idx))).ToList();
This could be more efficient if you use Split first:
var parts = str.Split('.');
var result = parts
.Select((x,idx) => new { idx })
.Select(p => string.Join(".",
parts.Skip(p.idx))).ToList();
You can also do it without creating anonymous type(s), just create an int variable:
int i = 0;
var result = parts
.Select(p => string.Join(".", parts.Skip(i++)))
.ToList();
This is fairly neat:
var text = "a.b.c.d.e";
var results =
text
.Split('.')
.Reverse()
.Scan("", (a, x) => x + "." + a)
.Select(x => x.TrimEnd('.'))
.Reverse();
You do need to add the Microsoft Reactive Extensions Team's "Interactive Extensions" to get the Scan operator. Use NuGet and look for "Ix-Main".
I actually kind of like this question, not necessarily production but a bit of brain-bendy fun:
"a.b.c.d.e".Split('.').Reverse()
.Aggregate(Enumerable.Empty<string>(), (acc, c) =>
acc.Concat(new [] { c+(acc.LastOrDefault()??"") })
).Reverse()
Dotnetfiddle
What this does is move through each character in the split array and build up a new array by prepending the last value in the array with the current character. It's a fairly common functional programming technique.
Well, this is how I might write it.. I know, not "one line", but if you're gonna use (and I do recommend) a method anyway..
IEnumerable<string> AllComponentPartsForward (string s) {
IEnumerable<string> p = s.Split('.');
while (p.Any()) {
yield return string.Join(".", p); // p.ToArray() for .NET 3.5
p = p.Skip(1);
}
}
(I suppose it could be "more efficient" with IndexOf/Substring, but that's also harder for me to write and reason about!)
Related
I have a bunch of SKUs (stock keeping units) that represent a series of strings that I'd like to create a single Regex to match for.
So, for example, if I have SKUs:
var skus = new[] { "BATPAG003", "BATTWLP03", "BATTWLP04", "BATTWSP04", "SPIFATB01" };
...I'd like to automatically generate the Regex to recognize any one of the SKUs.
I know that I could do simply do "BATPAG003|BATTWLP03|BATTWLP04|BATTWSP04|SPIFATB01", but list of SKUs can be quite lengthy and I'd like to compress the resulting Regex to look like "BAT(PAG003|TW(LP0(3|4)|SP04))|SPIFATB01"
So this is a combinatorics exercise. I want to generate the all of the possible Regex to match any of my input strings, with the view that the shortest is probably the best.
I could, for example, produce any of these:
BATPAG003|BATTWLP03|BATTWLP04|BATTWSP04|SPIFATB01
BAT(PAG003|TW(LP0(3|4)|SP04))|SPIFATB01
BAT(PAG003|TW(LP(03|04)|SP04))|SPIFATB01
B(ATPAG003|ATTW(LP0(3|4)|ATSP04))|SPIFATB01
Any of those would work, but the shortest is probably the one I'd choose.
To start with I've tried to implement this function:
Func<IEnumerable<string>, IEnumerable<string>> regexify = null;
regexify = xs =>
from n in Enumerable.Range(1, 10)
let g = xs.ToArray().Where(s => !String.IsNullOrWhiteSpace(s)).GroupBy(x => new String(x.Take(n).ToArray()), x => new String(x.Skip(n).ToArray()))
let parts = g.SelectMany(x => x.Count() > 1 ? regexify(x).Select(y => x.Key + "(" + String.Join("|", y) + ")") : new [] { x.Key + String.Join("", x) })
let regex = String.Join("|", parts)
orderby regex.Length
select regex;
This takes my source skus and results in a list of possible Regex's, but it's not working. This is the current output:
BATPAG003|BATTWLP03|BATTWLP04|BATTWSP04|SPIFATB01
BATPAG003|BATTWLP03|BATTWLP04|BATTWSP04|SPIFATB01
BATPAG003|BATTWLP0(3|4)|BATTWLP0(3|4)|BATTWLP0(3|4)|BATTWLP0(3|4)|BATTWLP0(3|4)|BATTWLP0(3|4)|BATTWLP0(3|4)|BATTWLP0(3|4)|BATTWLP0(3|4)|BATTWLP0(3|4)|BATTWSP04|SPIFATB01
BATPAG003|BATTWLP(03|04)|BATTWLP(03|04)|BATTWLP(03|04)|BATTWLP(03|04)|BATTWLP(03|04)|BATTWLP(03|04)|BATTWLP(03|04)|BATTWLP(03|04)|BATTWLP(03|04)|BATTWLP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|BATTWSP04|SPIFATB01
BATPAG003|BATTWL(P03|P04)|BATTWL(P03|P04)|BATTWL(P03|P04)|BATTWL(P03|P04)|BATTWL(P03|P04)|BATTWL(P03|P04)|BATTWL(P03|P04)|BATTWL(P03|P04)|BATTWL(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|BATTWL(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|BATTWSP04|SPIFATB01
BATPAG003|BATTW(LP03|LP04|SP04)|BATTW(LP03|LP04|SP04)|BATTW(LP03|LP04|SP04)|BATTW(LP03|LP04|SP04)|BATTW(LP03|LP04|SP04)|BATTW(LP03|LP04|SP04)|BATTW(LP03|LP04|SP04)|BATTW(LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|SP04)|BATTW(LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|SP04)|BATTW(L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|L(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|SP04)|SPIFATB01
BATPAG003|BATT(WLP03|WLP04|WSP04)|BATT(WLP03|WLP04|WSP04)|BATT(WLP03|WLP04|WSP04)|BATT(WLP03|WLP04|WSP04)|BATT(WLP03|WLP04|WSP04)|BATT(WLP03|WLP04|WSP04)|BATT(WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WSP04)|BATT(WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|WSP04)|BATT(WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|WL(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|WSP04)|BATT(W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|SP04)|W(LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|SP04)|W(L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|L(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|SP04))|SPIFATB01
BAT(PAG003|TWLP03|TWLP04|TWSP04)|BAT(PAG003|TWLP03|TWLP04|TWSP04)|BAT(PAG003|TWLP03|TWLP04|TWSP04)|BAT(PAG003|TWLP03|TWLP04|TWSP04)|BAT(PAG003|TWLP03|TWLP04|TWSP04)|BAT(PAG003|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWSP04)|BAT(PAG003|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|TWSP04)|BAT(PAG003|TWL(P03|P04)|TWL(P03|P04)|TWL(P03|P04)|TWL(P03|P04)|TWL(P03|P04)|TWL(P03|P04)|TWL(P03|P04)|TWL(P03|P04)|TWL(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|TWL(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|TWSP04)|BAT(PAG003|TW(LP03|LP04|SP04)|TW(LP03|LP04|SP04)|TW(LP03|LP04|SP04)|TW(LP03|LP04|SP04)|TW(LP03|LP04|SP04)|TW(LP03|LP04|SP04)|TW(LP03|LP04|SP04)|TW(LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|SP04)|TW(LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|SP04)|TW(L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|L(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|SP04))|BAT(PAG003|T(WLP03|WLP04|WSP04)|T(WLP03|WLP04|WSP04)|T(WLP03|WLP04|WSP04)|T(WLP03|WLP04|WSP04)|T(WLP03|WLP04|WSP04)|T(WLP03|WLP04|WSP04)|T(WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WSP04)|T(WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|WSP04)|T(WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|WL(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|WSP04)|T(W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|SP04)|W(LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|SP04)|W(L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|L(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|SP04)))|SPIFATB01
BA(TPAG003|TTWLP03|TTWLP04|TTWSP04)|BA(TPAG003|TTWLP03|TTWLP04|TTWSP04)|BA(TPAG003|TTWLP03|TTWLP04|TTWSP04)|BA(TPAG003|TTWLP03|TTWLP04|TTWSP04)|BA(TPAG003|TTWLP0(3|4)|TTWLP0(3|4)|TTWLP0(3|4)|TTWLP0(3|4)|TTWLP0(3|4)|TTWLP0(3|4)|TTWLP0(3|4)|TTWLP0(3|4)|TTWLP0(3|4)|TTWLP0(3|4)|TTWSP04)|BA(TPAG003|TTWLP(03|04)|TTWLP(03|04)|TTWLP(03|04)|TTWLP(03|04)|TTWLP(03|04)|TTWLP(03|04)|TTWLP(03|04)|TTWLP(03|04)|TTWLP(03|04)|TTWLP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|TTWSP04)|BA(TPAG003|TTWL(P03|P04)|TTWL(P03|P04)|TTWL(P03|P04)|TTWL(P03|P04)|TTWL(P03|P04)|TTWL(P03|P04)|TTWL(P03|P04)|TTWL(P03|P04)|TTWL(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|TTWL(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|TTWSP04)|BA(TPAG003|TTW(LP03|LP04|SP04)|TTW(LP03|LP04|SP04)|TTW(LP03|LP04|SP04)|TTW(LP03|LP04|SP04)|TTW(LP03|LP04|SP04)|TTW(LP03|LP04|SP04)|TTW(LP03|LP04|SP04)|TTW(LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|SP04)|TTW(LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|SP04)|TTW(L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|L(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|SP04))|BA(TPAG003|TT(WLP03|WLP04|WSP04)|TT(WLP03|WLP04|WSP04)|TT(WLP03|WLP04|WSP04)|TT(WLP03|WLP04|WSP04)|TT(WLP03|WLP04|WSP04)|TT(WLP03|WLP04|WSP04)|TT(WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WSP04)|TT(WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|WSP04)|TT(WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|WL(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|WSP04)|TT(W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|SP04)|W(LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|SP04)|W(L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|L(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|SP04)))|BA(T(PAG003|TWLP03|TWLP04|TWSP04)|T(PAG003|TWLP03|TWLP04|TWSP04)|T(PAG003|TWLP03|TWLP04|TWSP04)|T(PAG003|TWLP03|TWLP04|TWSP04)|T(PAG003|TWLP03|TWLP04|TWSP04)|T(PAG003|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWSP04)|T(PAG003|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|TWSP04)|T(PAG003|TWL(P03|P04)|TWL(P03|P04)|TWL(P03|P04)|TWL(P03|P04)|TWL(P03|P04)|TWL(P03|P04)|TWL(P03|P04)|TWL(P03|P04)|TWL(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|TWL(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|TWSP04)|T(PAG003|TW(LP03|LP04|SP04)|TW(LP03|LP04|SP04)|TW(LP03|LP04|SP04)|TW(LP03|LP04|SP04)|TW(LP03|LP04|SP04)|TW(LP03|LP04|SP04)|TW(LP03|LP04|SP04)|TW(LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|SP04)|TW(LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|SP04)|TW(L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|L(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|SP04))|T(PAG003|T(WLP03|WLP04|WSP04)|T(WLP03|WLP04|WSP04)|T(WLP03|WLP04|WSP04)|T(WLP03|WLP04|WSP04)|T(WLP03|WLP04|WSP04)|T(WLP03|WLP04|WSP04)|T(WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WSP04)|T(WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|WSP04)|T(WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|WL(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|WSP04)|T(W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|SP04)|W(LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|SP04)|W(L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|L(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|SP04))))|SPIFATB01
B(ATPAG003|ATTWLP03|ATTWLP04|ATTWSP04)|B(ATPAG003|ATTWLP03|ATTWLP04|ATTWSP04)|B(ATPAG003|ATTWLP03|ATTWLP04|ATTWSP04)|B(ATPAG003|ATTWLP0(3|4)|ATTWLP0(3|4)|ATTWLP0(3|4)|ATTWLP0(3|4)|ATTWLP0(3|4)|ATTWLP0(3|4)|ATTWLP0(3|4)|ATTWLP0(3|4)|ATTWLP0(3|4)|ATTWLP0(3|4)|ATTWSP04)|B(ATPAG003|ATTWLP(03|04)|ATTWLP(03|04)|ATTWLP(03|04)|ATTWLP(03|04)|ATTWLP(03|04)|ATTWLP(03|04)|ATTWLP(03|04)|ATTWLP(03|04)|ATTWLP(03|04)|ATTWLP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|ATTWSP04)|B(ATPAG003|ATTWL(P03|P04)|ATTWL(P03|P04)|ATTWL(P03|P04)|ATTWL(P03|P04)|ATTWL(P03|P04)|ATTWL(P03|P04)|ATTWL(P03|P04)|ATTWL(P03|P04)|ATTWL(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|ATTWL(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|ATTWSP04)|B(ATPAG003|ATTW(LP03|LP04|SP04)|ATTW(LP03|LP04|SP04)|ATTW(LP03|LP04|SP04)|ATTW(LP03|LP04|SP04)|ATTW(LP03|LP04|SP04)|ATTW(LP03|LP04|SP04)|ATTW(LP03|LP04|SP04)|ATTW(LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|SP04)|ATTW(LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|SP04)|ATTW(L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|L(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|SP04))|B(ATPAG003|ATT(WLP03|WLP04|WSP04)|ATT(WLP03|WLP04|WSP04)|ATT(WLP03|WLP04|WSP04)|ATT(WLP03|WLP04|WSP04)|ATT(WLP03|WLP04|WSP04)|ATT(WLP03|WLP04|WSP04)|ATT(WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WSP04)|ATT(WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|WSP04)|ATT(WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|WL(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|WSP04)|ATT(W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|SP04)|W(LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|SP04)|W(L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|L(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|SP04)))|B(AT(PAG003|TWLP03|TWLP04|TWSP04)|AT(PAG003|TWLP03|TWLP04|TWSP04)|AT(PAG003|TWLP03|TWLP04|TWSP04)|AT(PAG003|TWLP03|TWLP04|TWSP04)|AT(PAG003|TWLP03|TWLP04|TWSP04)|AT(PAG003|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWSP04)|AT(PAG003|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|TWSP04)|AT(PAG003|TWL(P03|P04)|TWL(P03|P04)|TWL(P03|P04)|TWL(P03|P04)|TWL(P03|P04)|TWL(P03|P04)|TWL(P03|P04)|TWL(P03|P04)|TWL(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|TWL(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|TWSP04)|AT(PAG003|TW(LP03|LP04|SP04)|TW(LP03|LP04|SP04)|TW(LP03|LP04|SP04)|TW(LP03|LP04|SP04)|TW(LP03|LP04|SP04)|TW(LP03|LP04|SP04)|TW(LP03|LP04|SP04)|TW(LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|SP04)|TW(LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|SP04)|TW(L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|L(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|SP04))|AT(PAG003|T(WLP03|WLP04|WSP04)|T(WLP03|WLP04|WSP04)|T(WLP03|WLP04|WSP04)|T(WLP03|WLP04|WSP04)|T(WLP03|WLP04|WSP04)|T(WLP03|WLP04|WSP04)|T(WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WSP04)|T(WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|WSP04)|T(WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|WL(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|WSP04)|T(W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|SP04)|W(LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|SP04)|W(L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|L(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|SP04))))|B(A(TPAG003|TTWLP03|TTWLP04|TTWSP04)|A(TPAG003|TTWLP03|TTWLP04|TTWSP04)|A(TPAG003|TTWLP03|TTWLP04|TTWSP04)|A(TPAG003|TTWLP03|TTWLP04|TTWSP04)|A(TPAG003|TTWLP0(3|4)|TTWLP0(3|4)|TTWLP0(3|4)|TTWLP0(3|4)|TTWLP0(3|4)|TTWLP0(3|4)|TTWLP0(3|4)|TTWLP0(3|4)|TTWLP0(3|4)|TTWLP0(3|4)|TTWSP04)|A(TPAG003|TTWLP(03|04)|TTWLP(03|04)|TTWLP(03|04)|TTWLP(03|04)|TTWLP(03|04)|TTWLP(03|04)|TTWLP(03|04)|TTWLP(03|04)|TTWLP(03|04)|TTWLP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|TTWSP04)|A(TPAG003|TTWL(P03|P04)|TTWL(P03|P04)|TTWL(P03|P04)|TTWL(P03|P04)|TTWL(P03|P04)|TTWL(P03|P04)|TTWL(P03|P04)|TTWL(P03|P04)|TTWL(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|TTWL(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|TTWSP04)|A(TPAG003|TTW(LP03|LP04|SP04)|TTW(LP03|LP04|SP04)|TTW(LP03|LP04|SP04)|TTW(LP03|LP04|SP04)|TTW(LP03|LP04|SP04)|TTW(LP03|LP04|SP04)|TTW(LP03|LP04|SP04)|TTW(LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|SP04)|TTW(LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|SP04)|TTW(L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|L(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|SP04))|A(TPAG003|TT(WLP03|WLP04|WSP04)|TT(WLP03|WLP04|WSP04)|TT(WLP03|WLP04|WSP04)|TT(WLP03|WLP04|WSP04)|TT(WLP03|WLP04|WSP04)|TT(WLP03|WLP04|WSP04)|TT(WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WSP04)|TT(WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|WSP04)|TT(WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|WL(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|WSP04)|TT(W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|SP04)|W(LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|SP04)|W(L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|L(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|SP04)))|A(T(PAG003|TWLP03|TWLP04|TWSP04)|T(PAG003|TWLP03|TWLP04|TWSP04)|T(PAG003|TWLP03|TWLP04|TWSP04)|T(PAG003|TWLP03|TWLP04|TWSP04)|T(PAG003|TWLP03|TWLP04|TWSP04)|T(PAG003|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWLP0(3|4)|TWSP04)|T(PAG003|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(03|04)|TWLP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|TWSP04)|T(PAG003|TWL(P03|P04)|TWL(P03|P04)|TWL(P03|P04)|TWL(P03|P04)|TWL(P03|P04)|TWL(P03|P04)|TWL(P03|P04)|TWL(P03|P04)|TWL(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|TWL(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|TWSP04)|T(PAG003|TW(LP03|LP04|SP04)|TW(LP03|LP04|SP04)|TW(LP03|LP04|SP04)|TW(LP03|LP04|SP04)|TW(LP03|LP04|SP04)|TW(LP03|LP04|SP04)|TW(LP03|LP04|SP04)|TW(LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|SP04)|TW(LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|SP04)|TW(L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|L(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|SP04))|T(PAG003|T(WLP03|WLP04|WSP04)|T(WLP03|WLP04|WSP04)|T(WLP03|WLP04|WSP04)|T(WLP03|WLP04|WSP04)|T(WLP03|WLP04|WSP04)|T(WLP03|WLP04|WSP04)|T(WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WLP0(3|4)|WSP04)|T(WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(03|04)|WLP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|WSP04)|T(WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P03|P04)|WL(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|WL(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|WSP04)|T(W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP03|LP04|SP04)|W(LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|LP0(3|4)|SP04)|W(LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(03|04)|LP(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4))|SP04)|W(L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P03|P04)|L(P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4)|P0(3|4))|L(P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(03|04)|P(0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)|0(3|4)))|SP04)))))|SPIFATB01
It feels very close, and I think I'm slightly doing something wrong.
This works if each SKU id have the same length.
// ...
string regexStr = Calculate(skus);
// ...
public static string Calculate(IEnumerable<string> rest) {
if (rest.First().Length > 0) {
string[] groups = rest.GroupBy(r => r[0])
.Select(g => g.Key + Calculate(g.Select(e => e.Substring(1))))
.ToArray();
return groups.Length > 1 ? "(" + string.Join("|", groups) + ")" : groups[0];
} else {
return string.Empty;
}
}
This is what I finally worked out:
var skus = new[] { "BATPAG003", "BATTWLP03", "BATTWLP04", "BATTWSP04", "SPIFATB01" };
Func<IEnumerable<IGrouping<string, string>>, IEnumerable<string>> regexify = null;
Func<IEnumerable<string>, IEnumerable<string>> generate =
xs =>
from n in Enumerable.Range(2, 20)
let g = xs.GroupBy(x => new String(x.Take(n).ToArray()), x => new String(x.Skip(n).ToArray()))
where g.Count() != xs.Count()
from r in regexify(g)
select r;
regexify = gxs =>
{
if (!gxs.Any())
{
return new [] { "" };
}
else
{
var rs = regexify(gxs.Skip(1)).ToArray();
return
from f in gxs.Take(1)
from z in new [] { String.Join("|", f) }.Concat(f.Count() > 1 ? generate(f) : Enumerable.Empty<string>())
from r in rs
select f.Key + (f.Count() == 1 ? z : $"({z})") + (r != "" ? "|" + r : "");
}
};
Then using this query:
generate(skus).OrderBy(x => x).OrderBy(x => x.Length);
...I got this result:
BAT(PAG003|TW(LP0(3|4)|SP04))|SPIFATB01
BAT(PAG003|TWLP0(3|4)|TWSP04)|SPIFATB01
BA(TPAG003|TTW(LP0(3|4)|SP04))|SPIFATB01
BAT(PAG003|TW(LP(03|04)|SP04))|SPIFATB01
BAT(PAG003|TW(LP03|LP04|SP04))|SPIFATB01
BAT(PAG003|TWLP(03|04)|TWSP04)|SPIFATB01
BATPAG003|BATTW(LP0(3|4)|SP04)|SPIFATB01
BA(TPAG003|TT(WLP0(3|4)|WSP04))|SPIFATB01
BA(TPAG003|TTW(LP(03|04)|SP04))|SPIFATB01
BA(TPAG003|TTW(LP03|LP04|SP04))|SPIFATB01
BA(TPAG003|TTWLP0(3|4)|TTWSP04)|SPIFATB01
BAT(PAG003|TWL(P0(3|4))|TWSP04)|SPIFATB01
BAT(PAG003|TWL(P03|P04)|TWSP04)|SPIFATB01
BATPAG003|BATT(WLP0(3|4)|WSP04)|SPIFATB01
BATPAG003|BATTW(LP(03|04)|SP04)|SPIFATB01
BATPAG003|BATTW(LP03|LP04|SP04)|SPIFATB01
BA(TPAG003|TT(WLP(03|04)|WSP04))|SPIFATB01
BA(TPAG003|TTWLP(03|04)|TTWSP04)|SPIFATB01
BAT(PAG003|TWLP03|TWLP04|TWSP04)|SPIFATB01
BATPAG003|BATT(WLP(03|04)|WSP04)|SPIFATB01
BA(TPAG003|TT(WL(P0(3|4))|WSP04))|SPIFATB01
BA(TPAG003|TT(WL(P03|P04)|WSP04))|SPIFATB01
BA(TPAG003|TT(WLP03|WLP04|WSP04))|SPIFATB01
BA(TPAG003|TTWL(P0(3|4))|TTWSP04)|SPIFATB01
BA(TPAG003|TTWL(P03|P04)|TTWSP04)|SPIFATB01
BATPAG003|BATT(WL(P0(3|4))|WSP04)|SPIFATB01
BATPAG003|BATT(WL(P03|P04)|WSP04)|SPIFATB01
BATPAG003|BATT(WLP03|WLP04|WSP04)|SPIFATB01
BATPAG003|BATTWLP0(3|4)|BATTWSP04|SPIFATB01
BATPAG003|BATTWLP(03|04)|BATTWSP04|SPIFATB01
BA(TPAG003|TTWLP03|TTWLP04|TTWSP04)|SPIFATB01
BATPAG003|BATTWL(P0(3|4))|BATTWSP04|SPIFATB01
BATPAG003|BATTWL(P03|P04)|BATTWSP04|SPIFATB01
The only problem with my approach was computation time. Some of my source lists have nearly 100 SKUs. Some of the runs were taking longer than I care to wait for and had to break it down into smaller chunks and then manually concatenate.
Take the entire list of all of your sku's and make a single ternary tree regex.
When you add or delete sku's, regenerate the regex. Maybe your database
generates on a weekly basis.
This utility makes a regex of 10,000 strings in less than half a second
and size is not important, it could be 300,000 strings.
For example, here is regex of 175,000 word dictionary.
Somewhat similar to this question:
Where do I put the "orderby group.key" in this LINQ statement?
Except I'm using Dynamic.Linq which makes this a bit harder. I have a bunch of data coming from a database and then I'm grouping by some field and then outputing the result. The problem is that the ordering of the groups seems to randomly jump around which isn't very convenient for the end-user. So taking inspiration from the linked question, if I had this:
string[] words = { "boy","car", "apple", "bill", "crow", "brown" };
// note the first non-dynamic select here was just because I don't think dynamic linq
// will support indexing a string like that and it's not an important detail anyway
var wordList = words.Select(w => new {FirstLetter = w[0], Word = w})
.GroupBy("new (FirstLetter)","Word");
foreach(IGrouping<object, dynamic> g in wordList)
{
Console.WriteLine("Words that being with {0}:",
g.Key.ToString().ToUpper());
foreach (var word in g)
Console.WriteLine(" " + word);
}
Console.ReadLine();
How would I get it to order the keys? At least part of the problem is that the dynamic GroupBy returns an IEnumerable. I thought it might be as easy as:
var wordList = words.Select(w => new {FirstLetter = w[0], Word = w})
.GroupBy("new (FirstLetter)","Word")
.OrderBy("Key");
But that gives me a System.ArgumentException (At least one object must implement IComparable.) when it hits the foreach loop.
My actual code in my project is a little more complicated and looks something like this:
var colGroup = row.GroupBy(string.Format("new({0})",
string.Join(",", c)), string.Format("new({0})",
string.Join(",", v)));
Where c is a list of strings that I need to group by and v is a list of strings that I need to select in each group.
Ok - this is one way to do it, but it might be a little to static to be useful. The problem is that I had this part:
.GroupBy("new (FirstLetter)","Word");
Using new because I can't use a value type as a key (I had another question about that: https://stackoverflow.com/a/26022002/1250301). When with the OrderBy("Key") part, the problem is that it doesn't have a way to compare those dynamic types. I could solve it like this:
var wordList = words.Select(w => new {FirstLetter = w[0].ToString(), Word = w})
.GroupBy("FirstLetter","Word")
.OrderBy("Key");
Making the key a string. Or like this:
var wordList = words.Select(w => new {FirstLetter = w[0], Word = w})
.GroupBy("new (FirstLetter as k)","Word")
.OrderBy("Key.k");
Making it order by something (a char) that is comparable.
I can make it work with my actual problem like this (but it's kind of ugly):
var colGroup = row.GroupBy(string.Format("new({0})", string.Join(",", c)),
string.Format("new({0})", string.Join(",", v)))
.OrderBy(string.Join(",", c.Select(ob => string.Format("Key.{0}", ob))));
I am not sure what you are trying to do, but is that syntax even compiling?
try:
string[] words = { "boy","car", "apple", "bill", "crow", "brown" };
var wordList = words.Select(w => new {FirstLetter = w[0], Word = w})
.GroupBy(x => x.FirstLetter, x => x.Word)
.OrderBy(x => x.Key);
Suppose I have a collection of strings.
List<string> lines = new List<string>(File.ReadAllLines("Test.txt"));
And a regular expression to search for a match in that collection:
Regex r = new Regex(#"some regular expression");
How can I get the indeces of elements, matching the regex?
I have three ideas.
1st:
var indeces1 = lines.Where(l => r.IsMatch(l))
.Select(l => lines.IndexOf(l));
foreach (int i in indeces1)
{
Console.WriteLine(i);//Do the index-based task instead...
}
What I don't like about it, is using IndexOf over the original collection. Am I wrong and it's OK?
var indeces2 = lines.Select((l, i) => new { Line = l, Index = i })
.Where(o => r.IsMatch(o.Line));
foreach (var o in indeces2)
{
Console.WriteLine(o.Index);//Do the index-based task instead...
}
It seems to be better than the 1st one, but is there a way to do the same thing without creating an anonymous object?
And the last one:
for (int i = 0; i < lines.Count; i++)
{
if (r.IsMatch(lines[i]))
{
Console.WriteLine(i);//Do the index-based task instead...
}
}
Actually I have this one working now. But as I do love LINQ, I wanted to have a LINQ way to do the same.
So is there a better LINQ way to do this simple task?
If you love LINQ, you can use Enumerable.Range for simpler:
var indexes = Enumerable.Range(0, lines.Count)
.Where(i => r.IsMatch(lines[i]));
Edit:
Instead of using File.ReadAllLines to get all lines into memory:
List<string> lines = new List<string>(File.ReadAllLines("Test.txt"));
If your file is large, you should consider to use ReadLines which is deferred execution for more efficient:
var lines = File.ReadLines("C:\\Test.txt"));
If you just need indices then why don't you try .Select(t => t.Index); in your option 2. (at the end) to get IEnumerable of indices only. You will get rid of the Anonymous object.
So your query would be:
var indeces2 = lines.Select((l, i) => new { Line = l, Index = i })
.Where(o => r.IsMatch(o.Line))
.Select(t => t.Index);
In this case I would go with your humble iterator version:
for (int i = 0; i < lines.Count; i++)
{
if (r.IsMatch(lines[i]))
{
Console.WriteLine(i);//Do the index-based task instead...
}
}
For this scenario, LINQ does not really reduce the line count and increase readability, in comparisson to option 3. So I would go for the simplest version in this case.
I have UK postcodes data and I would like to sort them alphabeticaly, when I do that the result is as follows;
N10-XX
N1-XX
N2-XX
N3-XX
N4-XX
N5-XX
What I want is that as follows;
N1-XX
N2-XX
N3-XX
N4-XX
N5-XX
N10-XX
Basicaly I need to add 0 at the begining of the number if it is 1 digit. like N1 should be N01 to be able to do that, what is the regexp pattern for that?
Many thanks.
Well if you are bent on using Regex, then this should do it
var text = #"N10-XX
N1-XX
N2-XX
N3-XX
N4-XX
N5-XX";
text = Regex.Replace(text, #"^N(\d)-", "N0$1-", RegexOptions.Multiline);
that said you obviously will be altering the original data, so I am not sure if this is even applicable
If you want to sort numerically, but preserve the original data, then you may need to do something like this
text.Split('\n')
.Select(o => new { Original = o, Normal = Regex.Replace(o, #"^N(\d)-", "N0$1-", RegexOptions.Compiled)})
.OrderBy(o => o.Normal)
.Select(o => o.Original)
I'm not sure from the example which numbers in the post code need to be ordered. here is some regex examples for valid uk post codes http://blogs.creative-jar.com/post/Valid-UK-Postcdoe-formats.aspx. if you incorporate this using the method above you should be able to do it.
Here is a sort function returning original string in natural(?) order.
List<string> list1 = new List<string>{ "N10-XX","N1-XX","N2-XX","N3-XX","N4-XX","N5-XX" };
List<string> list2 = new List<string>() { "File (5).txt", "File (1).txt", "File (10).txt", "File (100).txt", "File (2).txt" };
var sortedList1 = MySort(list1).ToArray();
var sortedList2 = MySort(list2).ToArray();
public static IEnumerable<string> MySort(IEnumerable<string> list)
{
int maxLen = list.Select(s => s.Length).Max();
Func<string, char> PaddingChar = s => char.IsDigit(s[0]) ? ' ' : char.MaxValue;
return
list.Select(s =>
new
{
OrgStr = s,
SortStr = Regex.Replace(s, #"(\d+)|(\D+)", m => m.Value.PadLeft(maxLen, PaddingChar(m.Value)))
})
.OrderBy(x => x.SortStr)
.Select(x => x.OrgStr);
}
I'm trying to write a dynamic sort of command line processor where I have a dictionary with keys being possible parameters, and the member being an Action where the string is the text between the parameters passed on the command line. Want to be able to add parameters just by adding the params array, and writing the action in the dictionary.
Yes I realize this is a pointless exercise in overcomplicating implementation to simplify maintenance. Mostly just trying to stress myself to learn more linq.
Here's my dictionary:
private static Dictionary<string[], Action<string>> _commandLineParametersProcessor = new Dictionary<string[], Action<string>>()
{
{
new string[] {"-l", "--l", "-log", "--log"},
(logFile) =>
{
_blaBla.LogFilePath = logFile;
}
},
{
new string[] { "-s", "--s", "-server", "--server" },
(server) =>
{
ExecuteSomething(server);
_blaBla.Server = server;
}
}
};
What's the most elegant mechanism to take string[] args and not just correlate the members that fall within any of the dictionary key arrays, but Aggregate((x,y) => string.Format("{0} {1}", x, y)) the sequence of elements (was thinking TakeWhile() fits in here somehow) inbetween the args[] members that would be Contain()ed in any of the keys arrays, and handing them into the action of the respective key's value member.
We have all written these little command line processors countless times, and while obviously a simple loop and switch is always more than adequate, this is again as I said an exercise trying to stress my linq skills. So please no complaints that I'm overengineering, that part is obvious.
Update:
To make this maybe a little easier, here is a non-linq way of doing what I'm looking for (may be imperfect, this is just winging it):
Action<string> currentAction;
string currentActionParameter;
for(int i = 0; i < e.Args.Length; i++)
{
bool isParameterSwitch = _commandLineParametersProcessor.Keys.Any((parameterChoices) => parameterChoices.Contains(e.Args[i]));
if (isParameterSwitch)
{
if (!string.IsNullOrEmpty(currentActionParameter) && currentAction != null)
{
currentAction(currentActionParameter);
currentAction = null;
currentActionParameter = "";
}
currentAction = _commandLineParametersProcessor[_commandLineParametersProcessor.Keys.Single((parameterChoices) => parameterChoices.Contains(e.Args[i]))];
}
else
{
currentActionParameter = string.Format("{0} {1}", currentActionParameter, e.Args[i]);
}
}
This is not an altogether bad approach, I just wonder if anyone can maybe simplify it a little using linq or otherwise, though this may be the simplest form i guess..
Borrowing half of Adam Robinson's answer (+1 btw), but realizing that the Dictionary will never be accessed by key, and you just want to run the Actions instead of building up a string...
var inputCommands = args
.Select((value, idx) => new { Value = value, Group = idx / 2 })
.GroupBy(x => x.Group)
.Select(g => new
{
Command = g.First().Value,
Argument = g.Last().Value
}).ToList();
inputCommands.ForEach(x =>
{
Action<string> theAction =
(
from kvp in commands
where kvp.Key.Contains(x.Command)
select kvp.Value
).FirstOrDefault();
if (theAction != null)
{
theAction(x.Argument);
}
}
kvp.Key.Contains really defeats the whole point of Dictionary. I'd re-design that to be a Dictionary<string, Action<string>>. Then you could say
inputCommands.ForEach(x =>
{
if (commands.ContainsKey(x.Command))
{
commands[x.Command](x.Argument);
}
}
PS: I can recall much more obtuse C# code that I have written than this.
I must admit the possibility that you want to collect the actions, instead of running them. Here is that code:
var todo =
(
from x in inputCommands
let theAction =
(
from kvp in commands
where kvp.Key.Contains(x.Command)
select kvp.Value
).FirstOrDefault()
where theAction != null
select new { TheAction = theAction, Argument = x.Argument }
).ToList();
Assuming you know that every command has a corresponding argument (so 'args' will always be in the format of
cmd arg (repeated)
You could do something ridiculous like this...
var output = args.Select((value, idx) => new { Value = value, Group = idx / 2 })
.GroupBy(x => x.Group)
.Select(g => new
{
Command = commands.FirstOrDefault(kvp =>
kvp.Key.Contains(g.First().Value)).Value,
Argument = g.Last().Value
})
.Where(c => c.Command != null)
.Aggregate(
new StringBuilder(),
(builder, value) =>
{
builder.AppendLine(value.Command(value.Argument));
return builder;
}).ToString();
But that is, frankly, the most obtuse bit of C# that I can recall ever writing, and not a very good way to teach yourself LINQ. Nonetheless, it will do what you're asking.
EDIT
Just realized (thanks to David B) that your key is a string[], not just a string, so I added some even more obtuse code that deals with that.