0

.txt ファイルのデータを検索して読み込み、置換し、表示するにはどうすればよいですか

txt.file の私のデータは

1010w23#Mild#UnknwonStreet#001234521

そして私はこれでそれを変えたい

1010w34#Mild#UnknownStreet#001235421

私はWindowsフォームアプリケーションを楽しんでおり、C#は初めてです

これを使った私のセーブデータ

string[] dataEmployee = new string[4];

dataEmployee[0] = txtIdEmployee.Text;
dataEmployee[1] = txtName.Text;
dataEmployee[2] = txtAddress.Text;
dataEmployee[3] = txtContact.Text;

string.Join("#", dataEmployee);

TextWriter writeDataEmployee = new StreamWriter(@"dataemployee.txt", true);
4

2 に答える 2

0

次のようなことを試してください。ただし、これ以上の情報がないと、正確に何が必要なのかわかりません。

string text = File.ReadAllText(fileName);    //fileName is the path to your txt file
string[] fields = text.Split('#');
fields[0] = fields[0].Replace("23", "34");
fields[3] = fields[3].Replace("45", "54");
txtResult.Text = String.Join("#", fields);    //txtResult is some textbox in your form
于 2013-04-24T08:49:38.647 に答える
0

以下のようにしてみてください、それはあなたを助けるでしょう...

フォームに と を作成4 Text boxesし、以下のように名前を付けます。one button

テキストボックス:

txtEmployeeIDFind
txtEmployeeIDReplace
txtContactReplace
txtContactFind

ボタン:

btnFindandReplace

フォームを実行すると、ユーザーは以下のようにテキストボックスに値を入力します

ここに画像の説明を入力

以下のButton click eventようなコーディングを書いて...

   private void btnFindandReplace_Click(object sender, EventArgs e)
    {
        string text = System.IO.File.ReadAllText("dataemployee.txt");
        text = text.Replace(txtEmployeeIDFind.Text, txtEmployeeIDReplace.Text).Replace(txtContactFind.Text, txtContactReplace.Text);
        System.IO.File.WriteAllText("dataemployee.txt", text);
    }
于 2013-04-24T09:01:11.953 に答える