我一直在研究文本分类系统,并试图读取文本文档中的单词,对其进行解析,将其保存到字典中,然后将其保存到 XML 中。
fileNames = openFileDialog1->FileNames;
StreamReader^ objReader = gcnew StreamReader(fileNames[0]);
String^ strReader = objReader->ReadToEnd(); //read it to a string
objReader->Close();
//cut the file up
String^ delimStr = L"\r,\t,\n,' ','.',','"; //pull out the return,tabs,newline
array<Char>^ delimiter = delimStr->ToCharArray();//transform into an array
array<String^ > ^ strSplit = strReader->Split(delimiter);//split up the file
System::Collections::IEnumerator^ myenum = strSplit->GetEnumerator();//get enumerators
Dictionary<String^, int>^ saveWords = gcnew Dictionary<String^, int>(StringComparer::InvariantCultureIgnoreCase);
int position=-1;
//output the file
while (myenum->MoveNext())//enumerate through it
{
position++;
try{
saveWords->Add((Convert::ToString(myenum->Current)),0);
}
catch (Exception ^){
//some code
}
}
那么,我应该如何做 XMLSerializer 呢?
PS对不起,如果代码是一团糟且未优化。我对这一切(文本解析、字典、XML)都很陌生,到目前为止,我只是想让它工作。