我想與其他14個文件一個每次比較文件1文件。我想要的是讀取file1並從14個文件中讀取其他文件然後找到兩個文件之間匹配的數量(字) 計算每個另外14個文件的字數(每次一個)比較與其他14個文件
我試了下面的代碼:
static void Main()
{
StreamReader objReader = new StreamReader(@"c:\basic_source.txt");
string filepath = "";
ArrayList arrText = new ArrayList();
while (filepath != null)
{
filepath = objReader.ReadLine();
if (filepath != null)
arrText.Add(filepath);
}
objReader.Close();
//string path;
//path = filepath;
// Read the file and display it line by line.
int found;
int count = 0;
string [] cc;
int basic_source_attr_no = 20;
float simi_degree;
string textData = File.ReadAllText(@"C:\expermentaldata\s3\attributes.txt");
int cnt = (WordCounting.CountWords1(textData));
string[] content = File.ReadAllLines(@"C:\expermentaldata\s3\attributes.txt");
//int cnt = content.Count();
string[] mastercontent = File.ReadAllLines(@"C:\basic_source.txt");
foreach (string con in content)
{
if (mastercontent.Contains(con))
{
found = 1;
count = count + found;
}
}
simi_degree = (basic_source_attr_no + cnt)/count;
try
{
simi_degree = (basic_source_attr_no + cnt)/count;
}
finally
{
Console.WriteLine(" ");
}
Console.WriteLine("external attribute no similar attributes simi_degree ");
Console.WriteLine("---------------------------------------------------------------");
Console.WriteLine(" {0} {1} {2} ", cnt, count, simi_degree);
Console.ReadLine();
}
}
public static class WordCounting
{
/// <summary>
/// Count words with Regex.
/// </summary>
public static int CountWords1(string s)
{
MatchCollection collection = Regex.Matches(s, @"[\S]+");
return collection.Count;
}
}
}
問題是什麼? –
這裏沒有問題。 – Yaur
和你的問題是什麼? – wiero