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.
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());
}
}