我正在爲Windows 8桌面構建應用程序,我正在閱讀文本文件,並且想要更改一個特定行,但不知道如何如此,因此我擁有的是文本文件說用c刪除文本文件中的特定行#
username|false
username|false
username|false
而我想要刪除中間的一行時,這是我到目前爲止;
StorageFolder folder = ApplicationData.Current.LocalFolder;
StorageFile storageFile = await folder.GetFileAsync("students.txt");
var text = await Windows.Storage.FileIO.ReadLinesAsync(storageFile);
var list_false = "";
foreach (var line in text)
{
string name = "" + line.Split('|')[0];
string testTaken = "" + line.Split('|')[1];
if (your_name.Text == name)
{
if (testTaken == "false") {
pageTitle.Text = name;
enter_name_grid.Opacity = 0;
questions_grid.Opacity = 1;
var md = new MessageDialog("Enjoy the test");
await md.ShowAsync();
}
else
{
the_name.Text = "You have already taken the test";
var md1 = new MessageDialog("You have already taken the test");
await md1.ShowAsync();
}
return;
}
else
{
list_false = "You're not on the list";
}
}
if (list_false == "You're not on the list") {
var md2 = new MessageDialog("You're not on the list");
await md2.ShowAsync();
}
請幫助,它完美地讀取名稱,並允許他們接受測試,我只是需要它來刪除正確的行。提前致謝!!
你是什麼意思「去掉中間線有事時」? – Tarec
@Tarec嗯,當他們輸入他們的名字時,如果有匹配,那麼我想要刪除與他們名字相對應的行 – user3263978