Form1の全コード
using System;
using System.Windows.Forms;
using System.IO;
namespace FileTest2
{
public partial class Form1 : Form
{
String[,] RCData = new String[50, 20];
public Form1()
{
InitializeComponent();
}
private void Button1_Click(object sender, EventArgs e)
{
int i, j;
if (OpenFileDialog1.ShowDialog() == DialogResult.OK)
{
using (Microsoft.VisualBasic.FileIO.TextFieldParser MyReader = new Microsoft.VisualBasic.FileIO.TextFieldParser(OpenFileDialog1.FileName))
{
MyReader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited;
MyReader.SetDelimiters("\t");
String[] currentRow;
i = 0;
while (MyReader.EndOfData != true)
{
try
{
currentRow = MyReader.ReadFields();
j = 0;
foreach (String currentField in currentRow)
{
RCData[i, j] = currentField;
if (j < 9) { j = j + 1; }
}
}
catch (InvalidCastException ex)
{
MessageBox.Show(ex.Message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
if (i < 49) { i = i + 1; }
}
}
String OutText = "";
for (i = 0; i < 49; i++)
{
for (j = 0; j < 9; j++)
{
OutText = OutText + RCData[i, j] + " , ";
}
OutText = OutText + "\r\n";
}
if (SaveFileDialog1.ShowDialog() == DialogResult.OK)
{
using (StreamWriter outfile = new StreamWriter(SaveFileDialog1.FileName))
{
outfile.Write(OutText);
}
}
}
}
}
}