对于每个循环字符串 [英] For each loop string
本文介绍了对于每个循环字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从我的网站获取文件内容:
I'm getting a file content from my website:
Dim client As WebClient = New WebClient()
Dim text = client.DownloadString("http://myurl.com/raw.php")
text
如下:
Line
Another Line
Test1
Test2
现在,我如何通过 text
变量运行循环,以便从每一行获得一个文本?
Now, how can I run a loop through the text
variable, to have a text from each line ?
我已经试过了:
Dim str As String() = text.Split(":::")
For Each line As String In str
MsgBox(line)
Next
我用 :::
完成每一行,但是这个方法看起来很丑,我希望有更好的解决方案吗?
And I was finishing each line with the :::
, but this method seems ugly and I hope there are better solutions?
推荐答案
vb.net 端使用 XML 的示例:
An example of the vb.net side if useing XML:
Dim doc As New System.Xml.XmlDocument
doc.Load("http://myurl.com/raw.php")
Dim list = doc.GetElementsByTagName("article")
For Each item As System.Xml.XmlElement In list
MsgBox(item.InnerText)
Next
示例 XML 架构:
<?xml version='1.0'?>
<!-- File generated at 22/11/2012 17:22 -->
<articleList>
<article>Hello</article>
<article>World</article>
<article>Fish</article>
</articleList>
现在切换到 XML 的另一个优势意味着将来可以更轻松地添加更多详细信息(例如文章标题、日期/时间、作者等).
Another advantage of switching to XML now will mean it will be easier to add more details in the future (like article header, date/time, auther etc).
这篇关于对于每个循环字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文