I’m trying to convert some Excel formulas into C# code, and I’m kind of lost…
I have the following:
SUMPRODUCT(1*(RIGHT(A1)={"a","e","i","n","y"}))
What exactly does that mean?
Here is what I know:
RIGHT(A1)returns the last character of the text inA1.SUMPRODUCT({1,2,3}, {4,5,6})returns1*4 + 2*5 + 3*6(something like a scalar product, right?)
but here is what I don’t understand:
If the text is Claude, for example…
RIGHT(A1)={"e","a","b","c","d"} returns TRUE
and
RIGHT(A1)={"a","b","e","c","d"} returns FALSE
I only changed the index position of the e character.
What is happening there?
What I’m not understanding?
Basically the formula is checking if the last character in cell
A1is any of the following characters: a, e, i, n, or y. TheSUMPRODUCTpart is important because it is a hack to check the entire array at once against the last character. When you strip that part out and just useRIGHT(A1)={"a","b","e","c","d"}, Excel actually only looks at the first entry in the array, checks to see if it’s a match, and returns immediately. So when ‘e’ is in the first position, you get True.SUMPRODUCTallows the checking to be applied across the entire array. Another way to see this would be to manually type it out into separate cells in a grid fashion like thisThe bottom right cell would contain a 1 if any of the characters a,e,i,n,y are at the end of the value in A1, or a 0 if not. I am manually performing the same logic as
SUMPRODUCTto get to the same result.So, how this would be accomplished in C#.Net: