2011-01-07 4 views
0

私は垂直リストからなるtxtファイルを持っています。このリストにはx個のグループが含まれていますが、標準では常に3つのエンティティで構成されています。txtファイルから収集したデータを書き換えますか?

例は以下の通り:

PANNEL A 
38 
2440 

として説明:

NAME 
WIDTH 
LENGTH 

三つの項目のリストは(リストがx量を含有することができるが)同一である:

NEW BEAM 
38 
2440 
WOOD 
22 
610 
ITEM A 
50 
1220 

私は今、次のように書かれた新しいtxtファイルを作成する必要があります:

(“NEW BEAM” is “38” x “2440”) 
(“WOOD” is “22” x “610”) 
(“ITEM A” is “50” x “1220”) 

私はVB.NETを使用してどのようにこれを行うのですか?ここで

答えて

0

は、私はそれについて移動したい方法は次のとおりです。

Private Sub DoWork(ByVal inputFile As String, ByVal outputFile As String) 
    '//The VB IDE confuses smart quotes with regular quotes so it gets hard to embed them in a string. 
    '//Instead we'll embed them as raw characters 
    Static LQ As Char = Chr(147) 
    Static RQ As Char = Chr(148) 

    '//Load our input file specifying that we want to read it and that we're willing to share it with other readers 
    Using FSInput As New System.IO.FileStream(inputFile, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read) 
     '//Bind a string-based reader to the stream. If you know the character encoding of the file you might want to specify that as the second paramter 
     Using SR As New System.IO.StreamReader(FSInput, True) 
      '//Create a stream to the output file specifying that we're going to write to it but other people can still read from it 
      Using FSOutput As New System.IO.FileStream(outputFile, IO.FileMode.Create, IO.FileAccess.Write, IO.FileShare.Read) 
       '//Create our output file using the UT8 encoding, this can be changed to something else if needed 
       Using SW As New System.IO.StreamWriter(FSOutput, System.Text.Encoding.UTF8) 
        '//Read the first line 
        Dim curLine = SR.ReadLine() 
        '//Create a loop that uses the curLine variable as well as the next two lines. 
        '//This method won't fail if there's bad data but might produce erroneous output 
        Do While Not String.IsNullOrEmpty(curLine) '//Use IsNullOrEmpty because the last line might be a blank line 
         '//Write our line of text 
         SW.WriteLine("({0}{2}{1} is {0}{3}{1} x {0}{4}{1})", LQ, RQ, curLine, SR.ReadLine(), SR.ReadLine()) 
         '//Read the next line and send back to the top of the loop 
         curLine = SR.ReadLine() 
        Loop 
       End Using 
      End Using 
     End Using 
    End Using 
End Sub 

そして、あなたがすることによって、このメソッドを呼び出すと思います:

DoWork("C:\Input.txt", "C:\Output.txt") 
関連する問題