-5

I have create a demo file, that you can download, and a page to see it running. What I need to have done, is that all the tags, need to be removed ONLY in the area (BBCode [code])

UPDATE: The code does not work with multiple BBCode tags. So if there is

[URL]
[Site]
[B]

Or anything else, the script below breaks all the tags. And will not process the page properly.

Here is the link to the demo page. http://www.cffcs.com/test/EE/Main.asp

Here is the link to the download .zip file. http://www.cffcs.com/test/EE/Request.zip

If someone can assist me with this, I will be mighty grateful.

The following code, is used, however, I found that it breaks everything else that is NOT involved in the '[code' section This is what is being used, of which can be found in the code file above.

Function ReplaceChar(strString)
    strString = Reggex(strString, "\[code=(.*?)\](.*?)\[\/code\]", "<code class=""$1"">$2</code>")
    ReplaceChar = strString
End Function



Function ProtectSQL(SQLString)
    SQLString = SQLString
    SQLString = Replace(SQLString, "'", "''") ' replace > with &gt;
    SQLString = Replace(SQLString, vblf,"<br>") ' replace vblf with <br /> (This is mainly used for Memo fields.
    SQLString = Trim(SQLString)
    ProtectSQL = SQLString
End Function


getText = ProtectSQL(request.form("Answers"))
bigString = ReplaceChar(getText)



'grab the left chunk of text starting to the position just after [code
startString = LEFT(bigString, INSTR(bigString, "<code ") + 6)
endString = RIGHT(bigString, LEN(bigString)-INSTR(bigString, "</code>")+1)
midString = REPLACE(bigString, endString, "")
midString = REPLACE(midString, startString, "")
midString = REPLACE(midString, "<br>",vbLf)
bigString = startString & midString & endString
user692942
  • 16,398
  • 7
  • 76
  • 175
Wayne Barron
  • 304
  • 4
  • 16
  • 1
    At least try to include a snippet of your code to show what you have tried so far, links can degrade some code should be included in the body of the post. This will also help those who come here looking for an answer to a similar question. – user692942 Mar 11 '15 at 20:39
  • Updated with code, that was provided by Jen, as well as the code in the project processing file. – Wayne Barron Mar 12 '15 at 05:37
  • Found The Issue. The code is breaking ALL the other BBCode that is being passed through it. So that is what the issue has been the entire blasted time. I just changed it to look for the [code] instead of and sent everything through a textarea, and wa-la, I saw all the other BBCode tags shinning through. So. That is the issue, the code does not work with BBCode tags. That is the Update – Wayne Barron Mar 12 '15 at 05:54
  • To fix the BBCode issue, you have to close the opening tag in the script. It cannot be left open, as it will attach itself to everything that has a tag in it and break it. bigString, " ") + 6) or bigString, "[code=sql] ") + 10) – Wayne Barron Mar 12 '15 at 06:43

1 Answers1

13

In classic ASP, all you need is a simple Replace().

strString = REPLACE(strString, "<br>", vblf)

If you want to do the replace only to a part of the string, it gets a little more complicated:

'grab the left chunk of text starting to the position just after [code
startString = LEFT(bigString, INSTR(bigString, "<code ") + 6)

'grab the right chunk of text starting just before the [/code
endString = RIGHT(bigString, LEN(bigString)-INSTR(bigString, "</code>")+1)

'clear out the beginning and end to just get the part between the code tags
midString = REPLACE(bigString, endString, "")
midString = REPLACE(midString, startString, "")

'replace the breaks 
midString = REPLACE(midString, "<br>",vbLf)

'put it all back together
bigString = startString & midString & endString

Instead of using replaces to get the midString apart from the bigger string, you could use a MID function to grab the middle of the string - see here for MID documentation: http://www.w3schools.com/vbscript/func_mid.asp To do that, you will also need to calculate the length of the middle string, using a combination of INSTR() and LEN() to get the positions: http://www.w3schools.com/vbscript/func_len.asp

user692942
  • 16,398
  • 7
  • 76
  • 175
Jen R
  • 1,527
  • 18
  • 23
  • 1
    Jen, It seems that, after I made the demo, and started using all the objects coming out of the database in the real-world project, that, well, it worked like it should within the demo that I have posted in the link above. However, when I run it in my actual project, it is breaking the URL links, and breaking everything else. So, what I am going to do is go through my code, and find out what in the heck is causing it to break your code. As there has to be something that is causing this issue. So. This is closed. Jen, your code works great!!!!!!!!!!! It is my code that is killing it Wayne – Wayne Barron Mar 12 '15 at 05:50
  • 2
    @JenR I think there are scenarios where your code might replace
    tags outside of a section. For example, if there is an ending tag with spaces somewhere (like < /code> or ).In such case your code might find an ending tag of another block, and it will process all the content in-between even if it was not really inside the current block
    – yms Mar 12 '15 at 11:47
  • Ah yes, I see that... I was working under the assumption that there was only one block, since that is the information that was in the original question. – Jen R Mar 12 '15 at 12:00