Heres a console aplication that basically does what you talking about. Its case sensitive, so when you are prompted for a number you would have to enter D40001 to get the name. This program basically enters the whole file into a arraylist and searches it. It could search your file using less memory (by not saving the information to the arraylist) with a few modifications.
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
private struct DXX
{
public string DXXNumber;
public string DXXName;
}
static void Main(string[] args)
{
ArrayList a = new ArrayList();
System.IO.StreamReader sr = new System.IO.StreamReader("C:/Documents and Settings/Jeromy/My Documents/MCSD Self paced training kit/Projects/CodeTextBuilder/CodeTextBuilder/dealers.tdl");
while (!sr.EndOfStream)
{
string s = sr.ReadLine();
char[] splitchars = { '~' };
string[] sarr = s.Split(splitchars);
DXX d = new DXX();
// This is assuming that your dxx number is always first and the name is always the 4th entry.
d.DXXNumber = sarr[0];
d.DXXName = sarr[3];
a.Add(d);
}
sr.Close();
System.Console.WriteLine("Enter the DXX code for the name you want to retrieve." +
" Enter 'done' if your finished searching");
string sin = System.Console.ReadLine();
string name = "";
bool found = false;
while (!sin.Equals("done"))
{
foreach (DXX dl in a)
{
if (dl.DXXNumber.Equals(sin))
{
found = true;
name = dl.DXXName;
break;
}
}
if (found)
{
System.Console.WriteLine("Name: " + name);
found = false;
}
else
System.Console.WriteLine("That entry is not found.");
System.Console.WriteLine("Enter the DXX code for the name you want to retrieve." +
"Enter 'done' if your finished searching");
sin = System.Console.ReadLine();
}
}
}
}