kevp75
asked on
Linq To Array Q...
Ok. I am trying desperately to get distinct values from an array.
So far... unsuccessfully.
Right now, I need to show
VW
Audi
but it shows all values... how can I select distinct values from this? here's the code with the example array
So far... unsuccessfully.
Right now, I need to show
VW
Audi
but it shows all values... how can I select distinct values from this? here's the code with the example array
Dim tmp = New String() {"VW|Jetta", "VW|Golf", "Audi|TT", "Audi|A4", "VW|Passat", "VW|Beetle"}
Dim _Qry = From n In tmp.Distinct
For Each item In _Qry
Response.Write(item & "<br />")
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
P.S.
You don't really need the "Model =" part of the Select. "Select Key" should accomplish the same.
You don't really need the "Model =" part of the Select. "Select Key" should accomplish the same.
ASKER
exaclty what I was aiming at.
Dim _Qry = (From n In tmp _
Group n By Key = n.Substring(0, n.IndexOf("|")) Into Group _
Select Key).Distinct
Gets me back
VW
Audi
thank yo9u very much!
Dim _Qry = (From n In tmp _
Group n By Key = n.Substring(0, n.IndexOf("|")) Into Group _
Select Key).Distinct
Gets me back
VW
Audi
thank yo9u very much!
ASKER
so.... how would I get the other side of the |?
I tried n.Substring(1, n.IndexOf("|")) but of course, all that did was get rid of the first letter... LOL
I tried n.Substring(1, n.IndexOf("|")) but of course, all that did was get rid of the first letter... LOL
ASKER
ok. never mind :) n.Substring(n.IndexOf("|") ) does it, I just have to replace the | with an empty string. Thanks!
>> n.Substring(n.IndexOf("|") ) does it, I just have to replace the | with an empty string. Thanks!
If you do:
then you won't have to do the replacement = )
If you do:
n.Substring(n.IndexOf("|") + 1) does it, I just have to replace the | with an empty string. Thanks!
then you won't have to do the replacement = )
*Sheesh* copy and paste....
Take out the extraneous text of course!
Take out the extraneous text of course!
ASKER
yea...figred that out a second after I posted that LOL
The following code only displays the 6 distinct ones:
Open in new window
Result:
VW|Jetta<br />
VW|Golf<br />
Audi|TT<br />
Audi|A4<br />
VW|Passat<br />
VW|Beetle<br />