Imports Microsoft.VisualBasic
Public Function GetFieldByBIN(sCardPAN As String, sDataTable As String) As String
Dim sCardMatch As String = String.Empty
Dim iTestBinLength As Integer
For iTestBinLength = 10 To 6 Step -1
sCardMatch = Mid(sCardPAN, 1, iTestBinLength) & " "
iStart = InStr(1, sDataTable, sCardMatch, vbBinaryCompare)
If iStart > 0 Then Exit For
iStart = InStr(1, sDataTable, sCardMatch, vbTextCompare)
iEnd = InStr(iStart, sDataTable, ",", vbTextCompare)
iEnd = Len(sDataTable) + 1
iStart = iStart + iTestBinLength + 1
GetFieldByBIN = Mid(sDataTable, iStart, iEnd - iStart)
Dim testClass As TestClass = New TestClass
Dim cardPrefix = testClass.GetFieldByBIN("1234561234561234", "123456 123457,12345612 123458")
Console.WriteLine("Card prefix = " + cardPrefix)
cardPrefix = testClass.GetFieldByBIN("1234561334561234", "123456 123457,12345612 123458")
Console.WriteLine("Card prefix = " + cardPrefix)
cardPrefix = testClass.GetFieldByBIN("1234561234561234", "")
Console.WriteLine("Card prefix = " + cardPrefix)