Click here to Skip to main content
15,920,801 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
please help me to find the name and its serial number into the files these name is given by user.There is any search or Find mentod in this system.io name space.
I tried in c sharp(c#) but not successed please sombody do something.



deepak kuamr choudhary
Posted
Comments
Mehdi Gholam 10-Oct-11 5:51am    
Please edit your question, as it does not make sense.
DaveAuld 10-Oct-11 6:03am    
What is the structure of the text file, is it one line per entry e.g. Name=SerialNumber or is there some other form of delimitter?
Bala Selvanayagam 10-Oct-11 8:29am    
You have not given the file (abc.txt) structure showing how the data is arranged and how do you expect us to help ?

Give the file structure and tell us clearly what you want to do and also what you have done - post the code you have tried out so that we can tell you where the issue is...
Xeshan Ahmed 10-Oct-11 8:33am    
please modify your question and clearly mention structure of you text file.

C#
StreamReader sr = new StreamReader("bc.txt");
           string line=null;
           Console.WriteLine("Enter the name you wnat to seach");
           string s = Console.ReadLine();

           int j = 0;

           while ((line = sr.ReadLine()) != null)
           {
               Console.WriteLine(line);

               if (line.Contains(s))
               {
                   j = 1;
               }
           }
           if (j == 1)
           {
               Console.WriteLine("String found:-"+" "+ s);
           }
           else
           {
               Console.WriteLine("String not found:-"+" "+ s);
           }
          Console.WriteLine("");
           sr.Close();
 
Share this answer
 
following code gives you starting index of your name in the file, for complete code send complete file structure.
C#
string Name="Xeshan";
StreamReader file=new StreamReader(@"c:\abc.txt");
string filecontent = file.ReadToEnd();
int StartIndex = filecontent.Contains(Name) ? filecontent.IndexOf(Name) : -1;
 
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