A program example of adding links to the URL in the string

zhaozj2021-02-16  35

We sometimes have such requirements. If we entered a text, such as: "Today, I visited the CCTV website: http://www.cctv.com" So, we hope to be able to automatically For our "http://www.cctv.com", the characters plus links, in fact, many websites have this feature, so Africa also tried to write such a small program, one can be used To make it easy, the other can provide a little source code for beginners, so the process of code is easy to understand, so there is a little Rosoto. Of course, the master will give an ad hit. Alder standing at: http://www.zydn.net/index.asp Welcome masters to criticize.

All right. Let's introduce the basic idea of ​​this program.

1. First, find any of the links in a paragraph, save them in an array

2. Find out the position in the text and store them in an array.

3. Based on these locations, a whole section is divided into a segment of one by one to insert a link in the middle.

4. Insert the link in the middle and combine the text of this section.

Ok, basic thinking is this, in fact, the first steps can be completed together, but for the procedure easy to understand, I will separate them.

For convenience, I made them a sub-function, and the name is called CTOU ()

usage:

1 Copy the following code to any location of the file,

2 If you want to add a link stored in the variable mydoc, you will use myDoc = CTOU (MyDoc).

code show as below:

Function ctou (mych) on error resume nextte1 = mychif inStr (te1, "_ blank") = 0 TENTE2 = LCase (TE1) ZCD = LEN (TE2) DIM Star (100), MyEnd (100), MyURL (100), TE3 (100, 2) for i = 1 to 100 cd = len (TE2) STA = INSTR (TE2, "http: //") if sta = 0 THEN STAR (i) = zcd 1 exit for end if Urla = MID (TE2, STA, 50) URCD = IRLA, "") IF urcd = 0 THEN URCD = IRCD = 0 THEN URCD = IRCD = IF URCD = 0 THEN URCD = INSTR (URLA, CHR (34)) IF URCD = 0 THEN URCD = IRL (URLA, "'") IF URCD = 0 THEN URCD = 50 MyURL (i) = MID (TE2, STA, URCD-1 ) Myen = sta urcd ifmen> = cd dam for te2 = Right (TE2, CD-MyEN 2) Next 'What some urlte2 = lcase (TE1) for II = 1 to i if myURL is found in a paragraph II) <> "".

转载请注明原文地址:https://www.9cbs.com/read-26124.html

New Post(0)