這是需要處理的文本文件的摘錄。需要完成的是程序 必須在這個文本文件中讀取並將其格式化爲一個規範。問題是我沒有太多的工作 與文本文件的體驗。這是示例輸入文件。在C#中將文本文件讀入數組中
BSA Security Definition - Operator Report Type 28
NBC 3RD QUARTER PROFILE REVIEW 2010
________________________________________________________________________________
Operator: ABAZ095
Number of entries: 149
User selection: Selected Items
________________________________________________________________________________
Search Criteria :-
Operator Name = BT%
Approval Status = Any
Enable Status = Any
One-time Pwd = Any
Profiles =
Units =
Printers =
Terminals =
________________________________________________________________________________
Operator ID = BTA020
Name = ASIA CHAMBEGA
Active profile = User_Disabled
Enable status = Disabled
Re-enable date = 31/12/36 00:00:00
Approval status = Approved
Last changed = 21/07/10 07:34:30
Last sign-on = 13/06/08 14:09:37
Calculated pwd = BD
One-time password = No
Assigned unit = None
Operator ID = BTAC002
Name = A KALATA (NBC)
Active profile = User_Disabled
Enable status = Disabled
Re-enable date = 31/12/36 00:00:00
Approval status = Approved
Last changed = 31/05/10 14:04:41
Last sign-on = n/a
Calculated pwd = B9
One-time password = No
Assigned unit = None
Operator ID = BTAK000
Name = AISHA KEJO
Active profile = NLCB_R6.0_ACCESSCTRL
Active profile = NLCB_R6.0_VERAUT_MBE
Enable status = Enabled
Re-enable date = n/a
Approval status = Approved
Last changed = 12/07/08 08:10:47
Last sign-on = 19/07/08 08:08:58
Calculated pwd = 8A
One-time password = No
Assigned unit = NLCB
Operator ID = BTAL001
Name = AMANDUS LIPILI
Active profile = User_Disabled
Enable status = Disabled
Re-enable date = 31/12/36 00:00:00
Approval status = Approved
Last changed = 01/07/10 08:39:03
Last sign-on = 11/11/09 08:25:07
Calculated pwd = 4B
One-time password = No
Assigned unit = None
當處理的輸出文件應如下所示:
BTAK000, AISHA KEJO, NLCB_R6.0_ACCESSCTRL
BTAK000, AISHA KEJO, NLCB_R6.0_VERAUT_MBE
正如你所看到的,所需要的一切數據,但只有運營商ID,姓名和活動的配置文件需要輸出被拉。 如果在文件中找到每個操作員標識,則結果需要打印到新行。如果用戶有超過1 活動配置文件,則必須將操作員標識和名稱和配置文件輸出到新行。如果用戶具有禁用的配置文件 ,則必須忽略數據。正如您從示例中所看到的,第一個單元被忽略,因爲它們被禁用。具有啓用satatus的 用戶就是例子。正如你可以看到的輸出示例。
我的想法是將數據拉到數組中,但只輸出操作員ID,名稱和配置文件。我該怎麼做呢?
這是我到目前爲止有:
Console.WriteLine("Enter Input File Location: " + "\n");
//Reads path specifed by the user for input.
string t = File.ReadAllText(Console.ReadLine());
//Splits file where there is an equals sign.
t = t.Replace("=", "");
//Removes all tabbed spaces.
t = t.Replace("\t", "");
//Removes any new lines.
t = t.Replace("\n", ",");
//Removes blank spaces.
t = t.Replace(" ", "");
//Removes the Underscore.
t = t.Replace("_", "");
//Removes any leading or trailing whitespaces.
t = t.Trim(',');
//Writes formatted file to a pre defined ouput file's location.
File.WriteAllText(@"C:/3rd Quarter1.txt", t);
請張貼鱈魚e迄今爲止你寫的。人們通常不喜歡只爲你寫代碼。事實上,這是一個工作描述,而不是一個問題。 – 2011-02-27 11:45:01
沒有人會爲你做你的工作。試一試,回來**具體的**編程問題。例如:「我如何從文本文件中讀取信息」或「如何將此文本行分隔爲多個部分,使用冒號作爲分隔符」 – jgauffin 2011-02-27 11:48:25
好的,我在這裏有代碼。它所做的基本上是拆分,刪除等號並對文本進行格式化,以便它從新行開始,即時遇到問題的是我不知道如何有選擇地選擇要輸出的信息。繼承人迄今爲止:見編輯quaeston – Paveetren 2011-02-27 12:08:24