我要做的是:从WebServer读取文本文件,获取内容并在带有分隔文本框的显示中显示...
我该怎么做?
该文件为:http://www.gruma.ufsm.br/gruma/cmsm/cmsm_2013110812.txt
内容为:日期,风速和累积雨
Public Function GetPage(ByVal PageURL As String) As String
Dim S As String = ""
Try
Dim Request As HttpWebRequest = WebRequest.Create(PageURL)
Dim Response As HttpWebResponse = Request.GetResponse()
Using Reader As StreamReader = New StreamReader(Response.GetResponseStream())
S = Reader.ReadToEnd
End Using
Catch ex As Exception
Debug.WriteLine("FAIL: " + ex.Message)
End Try
Return S
End Function
答案 0 :(得分:0)
如果您想list
all
来自lines
extrat
each
的{{1}}和line
,{{1} },Date
:
WindSpeed
如果您想检查当前RAin
文本文件中的格式化日期是无效日期,您不能 Dim postrequ As HttpWebRequest = CType(HttpWebRequest.Create("http://www.gruma.ufsm.br/gruma/cmsm/cmsm_2013110812.txt"), HttpWebRequest)
Dim responsea As HttpWebResponse
responsea = DirectCast(postrequ.GetResponse(), HttpWebResponse)
Dim postreqreader As New StreamReader(responsea.GetResponseStream())
Dim line As String = postreqreader.ReadLine
While (Not (String.IsNullOrEmpty(line)))
Dim mydate, windspeed, AcumulatedRain As String 'DAte , Wind,Rain
windspeed = line.ToString.Split(";")(1) 'Output : WInd Speed
AcumulatedRain = line.ToString.Split(";")(2) 'Output : Rain Acumulation
mydate = line.ToString.Substring(0, line.ToString.IndexOf(";")) 'Output : DATE
line = postreqreader.ReadLine
End While
它和date NOW() Today()
它......
答案 1 :(得分:-1)
使用以下代码:
' Get web response, I am just using a text file for brevity...
' Sample data: 22/11/2013;10k;100mm
Dim reader As StreamReader = New StreamReader("file.txt")
Dim line As String
Do
line = reader.ReadLine ' read each line of text file
' In Do...Until so check line is not nothing
If line IsNot Nothing Then
Dim parts As String() = line.Split(New Char() {";"})
' parts(0) = date, parts(1) = wind, parts(2) = rain
End If
Loop Until a Is Nothing
reader.Close()