Deleting hyperlink(s) in a string of code source [SOLVED]

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Deleting hyperlink(s) in a string of code source [SOLVED]

Post by atout66 » Tue Apr 08, 2014 5:52 pm

Hi to all,

I'm trying to code a script to remove hyperlinks in a code source I uploaded. But I don't know what's the best approach.
After the use of a lineOffset(), I get a string in a var I want to clean. So I've a list of tag to remove and that's OK.

Code: Select all

put "<li>" , "<i>" , "<b>" , "</b>" , "</i>" , "</li>" , "&#160;" , "</span>" into theTagsToRemove
I run a repeat loop and clean all that tags from the var. But what about links and <span> tag ?
Do you know a tutorial somewhere about that ? I made a search on the forum but it says "No suitable matches were found ."

Kind regards, Jean-Paul.
Last edited by atout66 on Tue Apr 08, 2014 8:07 pm, edited 1 time in total.
Discovering LiveCode Community 6.5.2.

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: Deleting hyperlink(s) in a string of code source

Post by atout66 » Tue Apr 08, 2014 6:49 pm

Here is what I code:

Code: Select all

get offset(aa,theLineToDealWith) -- search  aa = "<a href=" in the string theLineToDealWith
   if IT > 0 then -- there is a link(s)
      put IT into laPrimPos -- position of char  "<" in the string <theLineToDealWith>
      get offset(">",theLineToDealWith)
      delete char laPrimPos to IT of theLineToDealWith                         
   end if
It's OK, for one link only in the string, as I remove prior the tags "</a>".

Any idea how this script could be improved to continu if more links are in the string ?

Kind regards, Jean-Paul.
Discovering LiveCode Community 6.5.2.

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Deleting hyperlink(s) in a string of code source

Post by Thierry » Tue Apr 08, 2014 7:08 pm

atout66 wrote:Here is what I code:

Code: Select all

get offset(aa,theLineToDealWith) -- search  aa = "<a href=" in the string theLineToDealWith
   if IT > 0 then -- there is a link(s)
      put IT into laPrimPos -- position of char  "<" in the string <theLineToDealWith>
      get offset(">",theLineToDealWith)
      delete char laPrimPos to IT of theLineToDealWith                         
   end if
It's OK, for one link only in the string, as I remove prior the tags "</a>".

Any idea how this script could be improved to continu if more links are in the string ?
Bonsoir Jean-Paul,

Here is an old post which does the opposite of what you want :)
But this could may be help you to go further...

http://forums.runrev.com/phpBB2/viewtop ... 462#p89699

What you can do is keep the regex I did write, and use the replacetext().

Regards,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Deleting hyperlink(s) in a string of code source

Post by jacque » Tue Apr 08, 2014 7:26 pm

I cheat and let the engine do it. It usually works:

Code: Select all

set the htmltext of fld "temp" to tHTML
get the text of fld "temp"
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: Deleting hyperlink(s) in a string of code source

Post by atout66 » Tue Apr 08, 2014 7:42 pm

Merci Thierry. I tried to deal with your function but I went into an infinite loop :roll:
May be I should wait 'till tomorrow...

Kind Regards, Jean-Paul.
Discovering LiveCode Community 6.5.2.

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Deleting hyperlink(s) in a string of code source

Post by Thierry » Tue Apr 08, 2014 7:47 pm

atout66 wrote:Merci Thierry. I tried to deal with your function but I went into an infinite loop :roll:
May be I should wait 'till tomorrow...
with replaceText() you don't need the loop!
May be worth checking the dictionary :roll:

Otherwise, as you want to get rid of *all* tags,
try jacque's solution. I don't know if it works for all case,
but I have a strong tendancy to trust Jacque statements :)

Regards,
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: Deleting hyperlink(s) in a string of code source

Post by atout66 » Tue Apr 08, 2014 7:55 pm

Oui Thierry, c'est exact, and thanks to Jacqueline. Very interresting approach.
I can get the string in a "temp" field and now I expect to play with the properties of this field "temp" to see if I can remove the underline text, the color and so on...

Kind regards, Jean-Paul.
Discovering LiveCode Community 6.5.2.

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: Deleting hyperlink(s) in a string of code source

Post by atout66 » Tue Apr 08, 2014 8:06 pm

Ah ! Victoire :!:
The most easiest way to transform the color and underline text, in my case

Code: Select all

set the htmltext of fld "temp" to theLineToDealWith -- remove the links and <span> tags, every thing
put fld "temp" into myVarTmp -- clear the all formatting; color, underline, bold !
put myVarTmp into fld "leFinalTxt" -- retrieve the original text  

Again, thanks a lot Jacqueline and to all of you.

Kind regards, Jean-Paul.
Discovering LiveCode Community 6.5.2.

Post Reply