Example of adding a link to the URL in the string

Source: Internet
Author: User

Function ToLink (Str)
Dim re' Regular Expression object
Dim strContent
If IsNull (Str) Then Str = ""
Set RE = New RegExp 'create a regular expression object
With RE
. Global = true' search applies to the entire string
. IgnoreCase = true' search case-insensitive
StrContent = Str
'*************************************** ************************
'Mail Address link is automatically set
'*************************************** ************************
. Pattern = "([w] *) @ ([w.] *)"
StrContent =. Replace (strContent, "<A Href = 'mailto: $1 @ $2 '> $1 @ $2 </A> ")
'*************************************** ************************
'Automatic link settings
'*************************************** ************************
'====== Add the protocol name as required ======
Dim D (3), I
D (0) = "http"
D (1) = "ftp"
D (2) = "news"
D (3) = "mms"
'==========================================
For I = 0 To UBound (D)
. Pattern = D (I) + ": // ([w.] *)"
StrContent =. replace (strContent, "<A Href = '" + D (I) + ": // $1 'target = _ blank>" + D (I) + ": // $1 </A> ")
Next
'*************************************** ************************
End
Set RE = Nothing
ToLink = strContent
End Function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.