Jump to content

Replacing HTML Tag <font>


mail.h.shukla

Recommended Posts

Hi,I have to replace a string message to some HTML code.I have:<font size = 10>and I want to change this string to:<font size =10>I know how to change a simple string to html, like:I can easily change <font> to <font>, as this is a fixed length string.But not for <font size = 10> or for <font size = 10 color="red"> as this is not a fixed length string.Waiting for a positive response.

Link to comment
Share on other sites

One thing I forgot to include that I have to change "Only and only" one tag i.e. <font> not any other tag like <br>, <table> etc.It is working fine:myStr = Replace(myStr, "<font>", "<font>")if I do:myStr = Replace(myStr, "&lt", "<")myStr = Replace(myStr, "&gt", ">")It will solve the problem, but I need to change only <font> or related tag not other like <table> etc...

Link to comment
Share on other sites

EDIT: this isn't right. I'll think some more.I don't know VBS, but I know this is a job for a regex. If you can figure out how to replace this pattern with this text, it should work.patt = "<(font*)>"rt = "<$1>"

Link to comment
Share on other sites

My question is: why VBscript? and why <font> tags?VBscript only works for Internet Explorer and <font> tags are better replaced with CSS styling.

Link to comment
Share on other sites

Ingolme: I assumed OP was using VBS server side. It's an ASP option, yes? But I've just noticed we're in the Browser Scripting forum. Funny, I forget to look where I am sometimes. <shrug>Jesh: I don't know. Implementations vary. I tried mine out in Javascript (FF Error Console because it was the handiest) and it did the job. Yours returned nothing. But in VBS . . . ??? :)EDIT: I think it returned "nothing" because it returned a real tag, as it was meant to do, and the console seems to ignore tags.Try both, see what happens.EDIT: Use Jesh's version.FWIW, the native option is to find the first instance of the first substring, replace it, use that as an index to find the first instance of the second substring, replace it, and repeat till done. Eew.

Link to comment
Share on other sites

Jesh: I don't know. Implementations vary. I tried mine out in Javascript (FF Error Console) and it did the job. Yours returned nothing. But in VBS . . .
True. I just saw font* and thought "match f once, o once, n once, and t zero or more times. font.*?, to me, means match "font" and then do a lazy match on any other character zero or more times.I would think <(font*)> would match "<font>" but not "<font face='verdana' size='2'>" nor "<font >".
Link to comment
Share on other sites

My question is: why VBscript? and why <font> tags?VBscript only works for Internet Explorer and <font> tags are better replaced with CSS styling.
Yes boss, I know that VBScript works only and only on IE. But cant help it.Mine is a application which is already build using VBScript and it is that huge that it is not easy to change even the plateform and then start working.Talking about <html> tag, it is again the requirement of my project. And I think that I need to be with the requirement until it is changed by my boss... :) Again, I tried my patterns... And I am using Regular Expression right now and tried many patterns.... But I am far still away from my target. They are not working... :) Waiting for a positive response.
Link to comment
Share on other sites

Thank you all for giving your time on my task.This Regular expression Pattern worked for me:myRegExp.Pattern = "<font (\w|\s|\num|\75|\42|\55|\72|\73|\45)*>"where numbers are octal representation of some special characters which may be used in font tagThank you all for the help.... :) :)

Link to comment
Share on other sites

What does your entire code look like?
Dim strOutput strOutput = Test_Fields("TS_DESCRIPTION").Value Set myRegExp = New RegExp myRegExp.IgnoreCase = True myRegExp.Global = True myRegExp.Pattern = "<font(\w|\s|\num|\42|\45|\46|\54|\55|\61|\72|\73|\75)*>" ' Replace Font Pattern From the Text Set myMatches = myRegExp.Execute(strOutput) For Each myMatch in myMatches dim matchReplaced, matchFound matchFound = myMatch.Value matchReplaced = myMatch.Value matchReplaced = replace (matchReplaced, "<", "<") matchReplaced = replace (matchReplaced, ">", ">") strOutput = Replace(strOutput, matchFound, matchReplaced) Next msgBox ("after processing : " &Test_Fields("TS_DESCRIPTION").Value) 'Return the value of strOutputMay be I need to fire an onblur event...But I dont know how???
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...