hi friends i have created a code which searches for the particular word from two different files and creates a new file with the records in it but i am not able to search digits from the string the code of mine goes here:

StreamReader sr = new StreamReader(@"C:\Documents and Settings\jitendra\Desktop\RIC_SELL_080318.csv");  StreamReader sr1 = new StreamReader(@"C:\Documents and Settings\jitendra\Desktop\RIC_customer_20080318.csv");

 StreamWriter sw = new StreamWriter(@"C:\strings.txt");

 string strline = "";   string strline1 = "";            
string[] values = null; string[] _values = null;

  while (!sr.EndOfStream && !sr1.EndOfStream)
            {
                strline = sr.ReadLine();
                strline1 = sr1.ReadLine();

                values = strline.Split(',');
                _values = strline1.Split(',');

                if ((values.Length > 3 && values[2].StartsWith("52")) && (_values.Length > 3 && _values[2].StartsWith("52")))
                {
                    sw.WriteLine(values[0].ToString() +"\t\t"+ strline1);
                }

on increasing the string digit's of values[2].StartsWith("52") and _values[2].StartsWith("52") the file is created but it does not contain any record it is empty so can you plz help......

Make sure that you have atleast 4 tokens on the target line in each file, since you are checking to see if there are MORE than 3 in your code.

Next, make sure you Close() all the files when you are done. Closing it is what causes it to write to the disk. I suggest that you also Flush() the output file prior to closing it.

I copied/pasted your code into a workbench, created some text files with 4 tokens, and it worked fine as long as there were 4 tokens, and I flushed and closed the output file, otherwise..... you get a zero byte output file.

// Jerry

Hi guys...
I'm new in c# and i have some problems running this code.
What library do we have to include for StreamReader to work?

I hope you undertsood my question...

using System.IO;

hi Jerry shaw thanks for the help my code worked but there is one problem that on searching that complete digits from one file i have to match that digit from another file and on matching the code i have to write the record in another file. see the code which i have written

StreamReader sr = new StreamReader(@"C:\Documents and Settings\jitendra\Desktop\RIC_SELL_080318.csv"); // first file to open
            
            StreamReader sr1 = new StreamReader(@"C:\Documents and Settings\jitendra\Desktop\RIC_customer_20080318.csv"); // second file for opening

            StreamWriter sw = new StreamWriter(@"C:\strings.txt"); // creating a text file
string strline = "";
            string strline1 = "";

            string[] values = null;
            string[] _values = null;

            while (!sr.EndOfStream && !sr1.EndOfStream)
            {
                   strline = sr.ReadLine();
                  strline1 = sr1.ReadLine();

                   values = strline.Split(',');
                  _values = strline1.Split(',');

               if (values.Length > 3 && values[2].StartsWith("521222") && (_values.Length > 3 && _values[2].StartsWith("52")))
                 {
                     sw.WriteLine(strline.ToString() + "\t\t" + strline1.ToString());
                 }
            }
            sw.Flush(); 
            sw.Close();
            sr.Close(); sr1.Close();
        }

i have impleted this code but what happens is that when i want to match the digits of values[2].StartsWith("521222") with _values[2].StartsWith("521222") again i get the file created with no records what is the mistake i am creating i don't know please help me....

Place a debug-bookmark on the line that places strline.ToString() into sw. Run under debug and see if that line is ever executed. I think you will find that it is not.
In order for it to fall into that conditional statement the text line (after split) must have atleast (4) elements, and the text has to match. You can use the deguger to see why the condition fails.

IOW, it is not the streamwriter that has the problem.

// Jerry

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.