일부 데이터를 기반으로 텍스트 줄을 파일의 기존 줄로 바꾸고 싶습니다. 일부 코드 블록을 개발했지만 작동하지 않았습니다. 내 텍스트 파일은 다음과 같이이다 : -C#에서 동일한 텍스트 파일의 다른 줄로 한 줄 바꾸기
g_start-fd,g_start-cnst,g_start-eq,mv-mv_size,mv-mv_alloy,mv-mv_argmt,mv-mv_ps,xfrmr-kva,g_end-line_t,g_end-str_num,g_end-cmt,g_end-str_coord-Latitude,g_end-str_coord-Longitude
28F1Y,oh,mv oh,120,al,oh_3,P45R24,,i,P45R25,,9.53725695,-0.86668464
28F1Y,oh,mv oh,120,al,oh_3,P45R25,,i,P45R42,,9.5468355,-0.85948875
28F1Y,oh,mv oh,120,al,oh_3,P45R42,,i,P45R49,,9.55073989,-0.85625858
28F1Y,oh,mv oh,120,al,oh_3,P45R49,,a,P45R25,,,
28F1Y,oh,mv oh,120,al,oh_3,P45R54,,i,P45R55,,9.5544981,-0.85359626
28F1Y,oh,mv xfrmr,120,al,oh_3,P45R55,5000,e,P45R56,Substation,9.5549907,-0.85303108
28F1Y,ug,mv,185,al,xlpe_3,P45R56,,e,P45R55,,,
28F1Y,ug,mv,185,al,xlpe_3,P45R57,,s,P45R58,Take off from ring main,9.55387622,-0.8538622
28F1Y,oh,mv oh,120,al,oh_3,P45R58,,a,P45R73,,9.54513187,-0.86060037
28F1Y,oh,mv oh,120,al,oh_3,P45R73,,a,P45R77,,9.5417936,-0.86098952
28F1Y,oh,mv oh,120,al,oh_3,P45R77,,a,P45R80,,9.54144045,-0.85857346
28F1Y,oh,mv oh,120,al,oh_3,P45R80,,a,P45R86,,9.53675765,-0.85935176
28F1Y,oh,mv,120,al,oh_3,P45R86,,e,P45R80,,,
내 응용 프로그램 정지 작업이 코드 실행하면 코드 작업을 강제로
string fileName1 = "D:\\WriteTextWork\\Line1.txt"; ;
OpenFileDialog pfdg = new OpenFileDialog();
if (pfdg.ShowDialog() == DialogResult.OK)
{
fileName1 = pfdg.FileName;
}
if (File.Exists(fileName1))
{
StreamReader SR = new StreamReader(fileName1);
string Data = null;
int count = 0;
while ((Data = SR.ReadLine()) != null)
{
count++;
if (count > 1)
{
string CopyText = "";
String[] SplitData = Data.Split(',');
if (SplitData[9] != null && SplitData[11] != null)
{
CopyText = Data;
string data1 = SR.ReadLine();
//MessageBox.Show(CopyText);
}
using (StreamReader SR1 = new StreamReader(fileName1))
{
//var SW = new StreamWriter(resultString1);
string line;
while ((line = SR1.ReadLine()) != null)
{
//String TrimData2 = line.Trim();
String[] SplitText = line.Split(',');
if (SplitText[9] == SplitData[9] && SplitText[11] == null)
{
using (StreamWriter SW = new StreamWriter(resultString1))
{
SW.WriteLine(CopyText);
MessageBox.Show(CopyText);
SW.Close();
}
}
}
SR1.Close();
}
}
}
}
오류를 게시 할 수 있으며 코드의 어느 부분에서 오류가 발생합니까? – failedprogramming
"작동 중지"는 어떤 일이 일어날 지 기술적 설명이 아닙니다. 도움이 필요하면 프로그래머처럼 생각하고 기술적 인 관찰을 한 다음 궁금한 사항을보고해야합니다. –
중첩 된 판독기와 작성기를 작성하고 있습니다. 그것에 대해 생각해보십시오. 이해가 되니? 당신의 논리와 일치하는 동일한 레벨과 사본 줄에 1 명의 독자와 1 명의 작가를 고려하십시오. –