| View previous topic :: View next topic |
| Author |
Message |
MarkTrubo Contributor


Joined: 27 May 2001 Posts: 148 Location: Long Island, NY
|
Posted: Mon Nov 14, 2005 11:22 am Post subject: string.dll / search & replace question... |
|
|
I'm using string.dll (which by-the-way is amazing) in a program that put the paths to some cgi scripts into html pages provided by clients. The cgi scripts endup being integrated into the links in the html, so I need to isolate all the external links.
Works great -- im using these string functions (obviously complete in the program):
%%myFileContent = @string(FileToVar, @ITEM(LB))
@string(GetURL,%%myFileContent,EXT)
@string(NoDupes,
@string(RegxFind,
@string(Replace,
I'm able to find and fix all external links that are on a single line, but if there is a line break, no good. This is an example of the problem:
| Quote: | <DIV align=center><FONT face="Verdana, Arial, Helvetica, sans-serif"
color=#ffffff size=1>For more info - <A
href="http://www.somelinkhere.com/"><B><FONT
color=#ffff00>click here</FONT></B></A> |
This function, @string(GetURL,%%myFileContent,EXT), does find the href line in this case, but I need to replace the whole thing including the "<A ", which is where my problem lies do to the line break.
If this were on one line it would be fine:
<A href="http://www.somelinkhere.com/">
But since the html comes form clients, sometimes links are not on one line
like this:
<A
href="http://www.somelinkhere.com/">
Ideas? |
|
| Back to top |
|
 |
Dr. Dread Professional Member


Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Mon Nov 14, 2005 12:45 pm Post subject: |
|
|
When you run into this type of situation, I'd quote Yoda: Use the force...
... the force here being regular expressions. You can work wonders with those.
Use RegxReplace to format your text prior to doing the other manips. Or use RegxRepInFile on the entire file.
BTW - be sure to write your regular expressions right or you may mess up things badly.
Greetz
Dr. Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
| Back to top |
|
 |
MarkTrubo Contributor


Joined: 27 May 2001 Posts: 148 Location: Long Island, NY
|
Posted: Mon Nov 14, 2005 5:12 pm Post subject: |
|
|
I read the descriptions, but did not really understand them. Maybe I need a Redbull infusion to make my brain work! Could you give me an example that addresses the issue I described?
Sorry for being lame today, I'm just not seeing it! |
|
| Back to top |
|
 |
Dr. Dread Professional Member


Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Tue Nov 15, 2005 7:23 am Post subject: |
|
|
Well, if ya don't mind putting everything into 1 line, ya could use @string(Xwhite, [input file as var], [CTRL]). Real easy.
Or perhaps a regex like
repeat
%%infile = @string(RegxReplace, %%infile, "<A(.*?)"[\t\n\r\f]"(.*?)</A>", "<A $1 $2</A>",)
until @equal(@string(CountRep,),0)
%%infile = @string(Xwhite, %%infile,CTRL)
Greetz
Dr. Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
| Back to top |
|
 |
MarkTrubo Contributor


Joined: 27 May 2001 Posts: 148 Location: Long Island, NY
|
Posted: Tue Nov 15, 2005 11:09 am Post subject: |
|
|
1) Thanks -- I'll try it!
2) Look at that formula... I'm sure I would have guessed that.... NOT! Thanks again!!! |
|
| Back to top |
|
 |
MarkTrubo Contributor


Joined: 27 May 2001 Posts: 148 Location: Long Island, NY
|
Posted: Tue Nov 15, 2005 11:39 am Post subject: |
|
|
| OK, I put that in my program and yep, it worked fine. But, my HTML is all on one line. Anyway not to compress the html? |
|
| Back to top |
|
 |
Dr. Dread Professional Member


Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Tue Nov 15, 2005 12:38 pm Post subject: |
|
|
Of course, it's all in 1 line coz I left the CTRL parameter in the Xwhite function
BTW, this might be better:
| Code: | repeat
%%infile = @string(RegxReplace, %%infile, "<A([^>]*?)[\t\n\r\f]([^>]*?)>", "<A $1 $2>",)
until @equal(@string(CountRep,),0)
%%line = @string(Xwhite, %%infile,) |
Greetz
Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
| Back to top |
|
 |
MarkTrubo Contributor


Joined: 27 May 2001 Posts: 148 Location: Long Island, NY
|
Posted: Tue Nov 15, 2005 2:37 pm Post subject: |
|
|
| Dread... you are the man! That worked great. Thank you so much!!!! |
|
| Back to top |
|
 |
Dr. Dread Professional Member


Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Tue Nov 15, 2005 3:05 pm Post subject: |
|
|
Glad it worked out. As I told ya - use the force...
Greetz
Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|