0

ここの誰もがこれで私を助けることができます

入力ファイル

  Type Reference      
   WIN  00001  
   WIN  00001   
   WIN  00001  
   MAC  00001  
   MAC  00001  

基本的に、最初の3文字が等しくないかどうかを比較する必要があります

優先出力は

タイプリファレンス

   WIN  00001  
   WIN  00001   
   WIN  00001  

以下のコード

Dim fh As StreamReader
Dim os as string
fh = new StreamReader("haggis.txt")
Dim s As String = fh.ReadLine()
While not s Is Nothing
   os = s.Substring(0,3) 
   if os <> os then
      Console.WriteLine("Write here")
   else

   end if    

   s = fh.ReadLine
End While
fh.Close()
End Sub
4

2 に答える 2

1

previousOS 変数を宣言し、それと比較します。

例えば

Dim fh As StreamReader
Dim previousOS as string REM to see what previous os was
Dim os as string
fh = new StreamReader("haggis.txt")
Dim s As String = fh.ReadLine()
While not s Is Nothing
  previousOS = os 
  REM save the old os in this variable before assigning it to a new variable
  os = s.Substring(0,3) 
REM check if the new os is equal to the previousOS string (null check if it the first time read
if previousOS <> Nothing AndAlso previousOS <> os then
   Console.WriteLine("Write here")
else

end if    

s = fh.ReadLine
End While
fh.Close()
End Sub
于 2011-06-16T10:13:54.283 に答える
0

@Yet Another Geek、あなたは近くにいます。プログラムを閉じたくない場合は、ストリームを閉じてから、elseステートメントにExitSub呼び出しを入れることができます。これにより、サブと呼ばれるものに戻り、処理を続行できます。

于 2011-06-16T16:19:31.303 に答える