473,325 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Find URL in a string

Is there a built in function in .NET to find URL in a string so i can format
it as <a href="url" ?

useful for Forum Posts and other human entered text.

Mar 31 '06 #1
2 1729
Mike,

Regular expressions work well for this.

Something like:

Dim RegEx As New
System.Text.RegularExpressions.Regex("(href|url|sr c)\s*=\s*(?:(?:\""(?<url>[^\""]*)\"")|(?<url>[^\s*]
))", System.Text.RegularExpressions.RegexOptions.Ignore Case Or
System.Text.RegularExpressions.RegexOptions.Compil ed)

Dim Matches As System.Text.RegularExpressions.MatchCollection =
RegEx.Matches(html)

Regards,
--
S. Justin Gengo
Web Developer / Programmer

Free code library:
http://www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Mike Kansky" <po********@zazasoftware.com> wrote in message
news:e%****************@TK2MSFTNGP12.phx.gbl...
Is there a built in function in .NET to find URL in a string so i can
format it as <a href="url" ?

useful for Forum Posts and other human entered text.

Mar 31 '06 #2
Killer method i just found:
Imports System.Text.RegularExpressions
Return Regex.Replace(sURL, "(\bhttp://[^ ]+\b)", "<a href=""$0"">$0</a>")

COOL!



"S. Justin Gengo" <justin@[remove to send mail]aboutfortunate.com> wrote in
message news:Om**************@TK2MSFTNGP10.phx.gbl...
Mike,

Regular expressions work well for this.

Something like:

Dim RegEx As New
System.Text.RegularExpressions.Regex("(href|url|sr c)\s*=\s*(?:(?:\""(?<url>[^\""]*)\"")|(?<url>[^\s*]
))", System.Text.RegularExpressions.RegexOptions.Ignore Case Or
System.Text.RegularExpressions.RegexOptions.Compil ed)

Dim Matches As System.Text.RegularExpressions.MatchCollection =
RegEx.Matches(html)

Regards,
--
S. Justin Gengo
Web Developer / Programmer

Free code library:
http://www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Mike Kansky" <po********@zazasoftware.com> wrote in message
news:e%****************@TK2MSFTNGP12.phx.gbl...
Is there a built in function in .NET to find URL in a string so i can
format it as <a href="url" ?

useful for Forum Posts and other human entered text.


Mar 31 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: hokieghal99 | last post by:
import os, string print " " setpath = raw_input("Enter the path: ") def find_replace(setpath): for root, dirs, files in os.walk(setpath): fname = files for fname in files: find =...
8
by: Jaime Wyant | last post by:
Will someone explain this to me? >>> "test".find("") 0 Why is the empty string found at position 0? Thanks! jw
3
by: Chris Mantoulidis | last post by:
I posted this here one day ago but it seems like it hasn't been put up for some unknown reason. That gives me a chance to say things a bit better in this post. 1st of all let's desribe the...
3
by: Prakash Bande | last post by:
Hi, I have bool operator == (xx* obj, const string st). I have declared it as friend of class xx. I am now able to do this: xx ox; string st; if (&ox == st) { } But, when I have a vector<xx*>...
108
by: Bryan Olson | last post by:
The Python slice type has one method 'indices', and reportedly: This method takes a single integer argument /length/ and computes information about the extended slice that the slice object would...
4
by: KL | last post by:
Hello again, I am still working on this homework assignment and have hit a wall. I have a list that I want to fill with all occurences of img tags from a big string of html code. So I have a...
7
by: tehn.yit.chin | last post by:
I am trying to experiment <algorithm>'s find to search for an item in a vector of struct. My bit of test code is shown below. #include <iostream> #include <vector> #include <algorithm>...
14
by: micklee74 | last post by:
hi say i have string like this astring = 'abcd efgd 1234 fsdf gfds abcde 1234' if i want to find which postion is 1234, how can i achieve this...? i want to use index() but it only give me the...
1
by: vmoreau | last post by:
I have a text and I need to find a Word that are not enclosed in paranthesis. Can it be done with a regex? Is someone could help me? I am not familar with regex... Example looking for WORD:...
11
by: Ko van der Sloot | last post by:
Hello I was wondering which behaviour might be expected (or is required) for the following small program. I would expect that find( "a", string::npos ) would return string::npos but is seems to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.