开发者

Extracting HTTP link(http://) for the string in VB.NET

I have the following column values in my table

Sample values:

  1. Check out ABC Group Blog post about XYZ Today! http://blog.saedg.org/

  2. 'Join ABC in urging the county to help create new jobs and economic opportunities for XYZCounty. http://starabcnet.com/news/science/environment/article_4b3d2f7e-96c6-5007-a036-b4613250755e.html

I want to have 2 variables having the links and content separate – example:

  1. Var1 = Check out ABC Group Blog post about XYZ Today!

    Var2 = http://blog.saedg.org/

  2. Var1 = Join ABC in urging the county to help create new jobs and economic opportunities for XYZCounty

    Var2 = http://starabcnet.com/news/science/environment/article_4b3d2f7e-96c6-5007-a036-b4613250755e.html

I guess it can be done via String funcions or r开发者_运维问答egular expression.


Try this:

' This is the regex that is used to get the addresses
Public Shared URL As New Regex("(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])", RegexOptions.Compiled)

' URL.Matches returns a collection of results that you can iterate through eg:
for each ele in URL.Matches("INPUT STRING")
    ' do something with each link that you get 
    ' like removing them from the input string
next


Can you separate the column in two different columns? Like, "Message" and "Link" for example.

If you can not do that, assuming the Http is always in the end of string and there is no other reference to HTTP:// in the string, you can get the string after "HTTP://".

Look at IndexOf and Substring methods of string in VB.NET.

Something like this (I didn't test):

string url = var.SubString(var.IndexOf("http"))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜