我想從一個文本文件中的數據爲出生日期的員工,我有在字符串中的所有其它信息出現在我的形式,但不DOB。以下是使用流讀取器獲取數據的代碼。獲取數據的形式C#
public bool Load(string employeesFile)
{
List<string> lines = new List<string>();
using (StreamReader reader = new StreamReader("employees.txt"))
{
string line;
while ((line = reader.ReadLine()) != null)
{
//Splitting the data using |
string[] temp = line.Split('|');
//This is to populate an employees detials
Employee emp = new Employee()
{
firstName = temp[0],
lastName = temp[1],
address = temp[2],
postCode = temp[3],
phoneNumber = temp[4],
//dateOfBirth = temp.ToString[5]
};
接下來是在表單中顯示數據的窗體中的代碼。
public partial class Salaried_Employee_Details : Form
{
public Salaried_Employee_Details(Employee emp)
{
InitializeComponent();
textBoxLastName.Text = emp.lastName;
textBoxFirstName.Text = emp.firstName;
textBoxAddress.Text = emp.address;
textBoxPostCode.Text = emp.postCode;
textBoxPhoneNumber.Text = emp.phoneNumber;
dateTimeDateOfBirth.Text = emp.dateOfBirth.ToString();
該文件中出生日期的格式爲1995 | 5 | 22。
我如何得到它從文本文件鏈接的形式展現?
不要發佈您的代碼的圖像。這使我們無法測試它。代碼只是文本。只需將其添加到您的問題(IE複製/粘貼) – Steve
添加您的員工類和你分裂的問題的字符串 –
提供至少一行文件employees.txt。我認爲你需要像'temp [5] +「/」+ temp [6] +「/」+ temp [7]'這樣的連續分割。 – PiLHA