Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   How to remove index numbers from each line of text file (http://www.go4expert.com/forums/remove-index-line-text-file-t28949/)

near 28Aug2012 08:08

How to remove index numbers from each line of text file
 
Hi,
I have a text file in which there are 10000 lines. There are 225 numerical values on each line and each numerical value is followed by a index number and a colon e.g., 1:0.021354 2:0.125432 3:451321 ...... 225:0.001254.
Now I want to remove this indexing. I know how to add indexing but could not perform to remove that. Please help me in solving this problem. Thanks
Here is the code for adding indexing.
Code:

static void Main(string[] args)
        {
            string[] files = Directory.GetFiles(@"F:\New folder", "*.txt", SearchOption.AllDirectories);

            StringBuilder strFile = new StringBuilder();

            foreach (string file in files)
            {
                using (StreamReader sr = new StreamReader(file))
                {
                    string s = Path.ChangeExtension(file, null);
                    strFile.AppendFormat(s.Substring(s.LastIndexOf(@"\") + 1) + " ");
              //      string s = Path.GetFileName("-1");
              //      strFile.AppendFormat(s + " ");
                    char[] charsToTrim = { ' ', '\r', '\n' };
                    string kkj = (sr.ReadToEnd().TrimEnd(charsToTrim));
                    string[] words = kkj.Split(' ');
                    string temp = "";

                    int iCounter = 1;

                    foreach (string word in words)
                    {
                        if (word.Contains("-0.000000"))
                        {
                            temp = word.Replace("-0.000000", "");

                            strFile.Append(temp);

                            iCounter++;
                            continue;
                        }

                        else if (word.Contains("0.000000"))
                        {
                            temp = word.Replace("0.000000", "");


                            strFile.Append(temp);

                            iCounter++;
                            continue;
                        }

                        strFile.Append(iCounter++ + ":" + word + " ");

                    }
                    strFile.AppendLine();
                }
            }
            using (StreamWriter outfile = new StreamWriter(@"F:\New folder (3)\-1.train"))
            {
                outfile.Write(strFile.ToString());
            }
        }



All times are GMT +5.5. The time now is 11:37.