내 용도는 따옴표 붙일 데이터가 들어있는 파일의 위치를 탐색하여 텍스트 파일에서 데이터를 읽는 것입니다. 파일의 데이터는 목록에 저장됩니다.하나의 열에있는 텍스트 파일에 데이터를 쓰는 중 논리적 오류가 발생했습니다.
'20050000',
'40223120',
'40006523'
But my code is currently displaying the output in the format:
'20050000'20050000,
'40223120'20050000,
'40006523'40006523
Pls는 도움말 : 내가
Example of a string:
20050000
40223120
40006523
샘플을 넣어 아래 demostrated으로 다음 단일 컬럼에 데이터를 저장하는 출력 파일을 만들 ArrayList를 통해 데이터 및 루프를 얻을 수 및 각 문자열을 연결하는 ArrayList를를 사용 . 당신이 나쁜 루프가 button2_Click 당신의 방법에서
public List<string> list()
{
List<string> Get_Receiptlist = new List<string>();
String ReceiptNo;
openFileDialog1.ShowDialog();
string name_of_Textfile = openFileDialog1.FileName;
try
{
StreamReader sr = new StreamReader(name_of_Textfile);
{
while ((ReceiptNo = sr.ReadLine()) != null)
{
Get_Receiptlist.Add(ReceiptNo);
} // end while
MessageBox.Show("Record saved in the Data list");// just for testing purpose.
}// end StreamReader
}
catch (Exception err)
{
MessageBox.Show("Cannot read data from file");
}
return Get_Receiptlist;
}
private void button2_Click(object sender, EventArgs e)
{
string single_quotation = "'";
string comma = ",";
string paths = @"C:\Users\sample\Desktop\FileStream\Output.txt";
if (!File.Exists(paths))
{
// Create a file to write to.
using (StreamWriter sw = File.CreateText(paths))
{
string[] receipt = list().ToArray();
foreach (string rec in receipt)
{
string quoted_receipt = single_quotation + rec + single_quotation + rec + comma;
sw.WriteLine(quoted_receipt);
sw.WriteLine(Environment.NewLine);
}//foreach
sw.Close();
MessageBox.Show("Finish processing File");
}//end using
}// end if
}
코드의 관련 부분을 제공해야합니다. – user1697575
방금 코드를 게시했습니다. 나는 밖으로했다 – kombo