下面是輸入文件字符串操作VB.net
DELL NOTEBOOK
1000 USD
ACER NOTEBOOK
HP NOTEBOOK
APPLE MOBILE
900 USD
HTC MOBILE
800 USD
基本上我需要檢查是否有第二行的任何單詞「USD」,並把 字是或在第一行號。 預期低於輸出
DELL NOTEBOOK YES
1000 USD
ACER NOTEBOOK NO
HP NOTEBOOK NO
APPLE MOBILE YES
900 USD
HTC MOBILE YES
800 USD
是我的代碼需要一些調整
Sub Main()
Dim fh As StreamReader
fh = new StreamReader("list.txt")
dim currency as string
dim bCurrency as boolean
Dim s As String = fh.ReadLine()
While not s Is Nothing
currency = s.substring(5,3)
if currency = "USD" then
bCurrency = True
else
if bCurrency = true then
Console.WriteLine(s & " Yes")
bCurrency = False
else
Console.WriteLine(s & " No")
end if
end if
s = fh.ReadLine
End While
fh.Close()
End Sub
Ahmad-San將保存到另一個文本文件。 – user801207
更新了代碼以包含兩種方法。你可以註釋掉你不想使用的那個 – Ahmad
Ahmad-San,最後一行沒有寫? – user801207