[英]Find first use of particular word in string & then display image url which is exacly after it(VB.Net)
我有一個包含網頁原始HTML的字符串。 我想搜索字符串中的/ imgres?imgurl =的首次使用,並在文本框中顯示緊隨其后的圖像的url。 以下是部分字符串的示例:
href =“ /imgres?imgurl=http://www.pic.com/pic.jpg&imgrefurl=http
在這種情況下,它將找到/ imgres?imgurl =,然后在文本框中顯示http://www.pic.com/pic.jpg 。
請注意,/ imgres?imgurl =在字符串中出現約20次,我只想第一次使用。
為什么要麻煩reg ex。
如果您已經有一個字符串,請執行以下操作:
Dim myString as String = "my long html text...."
Dim start as Int32 = myString.IndexOf("/imgres?imgurl=")
myString = myString.Substring(start + 15)
Dim end as Int32 = myString.IndexOf("&imgref")
myString = myString.Substring(0, end)
可以對其進行重大優化,但應該為您指明正確的方向
只是一個猜測... /imgres?imgurl=(.+?)&
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.