Click here to Skip to main content
15,915,324 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Every


VB
Dim arrayHex() As String = {"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0A", "0B", "0C", "0D", "0E", "0F", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1A", "1B", "1C", "1D", "1E", "1F"}


VB
Dim str As String  = "02" 


I want to find a str position in String array through Linq

Thanks in advance.
Posted
Updated 21-Dec-14 18:03pm
v2
Comments
PIEBALDconsult 22-Dec-14 0:06am    
While I wouldn't use Linq anyway, I really don't see why you wouldn't simply index into the array with that particular data.
E.g. Parse "02" to get 2 and then use arrayHex ( 2 ) -- no searching necessary.

VB
Dim arrayHex As String() = {"00", "01", "02", "03", "04", "05", _
	"06", "07", "08", "09", "0A", "0B", _
	"0C", "0D", "0E", "0F", "10", "11", _
	"12", "13", "14", "15", "16", "17", _
	"18", "19", "1A", "1B", "1C", "1D", _
	"1E", "1F"}
Dim test As string = "08"
Dim query = arrayHex.Select(Function(o,i) New With { .Hex = o, .Index = i}) _
                      .FirstOrDefault(Function(item) item.Hex = test)
If query Is Nothing
    Console.WriteLine("Item not found")
Else
    Console.WriteLine("Item found at index {0}", query.Index)
End If

'Item found at index 8
 
Share this answer
 
Hi

I think no need to LINQ here. you can make use of Array.IndexOf function.

refer Array.IndexOf in VB[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900