www.webdeveloper.com
Results 1 to 7 of 7

Thread: asp string replace in recordset

  1. #1
    Join Date
    Oct 2005
    Posts
    42

    asp string replace in recordset

    hi!

    im using this example from the w3c website...

    Code:
    <%
    dim txt
    txt="This is a beautiful day!"
    response.write(Replace(txt,"beautiful","horrible"))
    %>
    it works, however, i need to adapt it, and not sure how. basicly, i want to make like a swear word filter for a guestbook....
    so lets say txt = recordset("post") - and i did
    Code:
    response.write(Replace(txt,"naughty_word","_a_good_word"))
    thats fine. however, there are many more words then this....how would i adapt this code to do more replaces in that string. copying the replace line just writes the details again...

    thanks all!

  2. #2
    Ubik's Avatar
    Ubik is offline &lt;%= &quot;New Meja Hor&quot; %&gt;
    Join Date
    Nov 2005
    Location
    Earth
    Posts
    361
    PHP Code:
    strTextToBeCleaned recordset("post")
    strCleanText strTextToBeCleaned
    strSwearWordList
    ="beep, boop, bleep, bop, sheboing, ppppffft, bang"
    astrSwearWordList=split(astrSwearWordList)
    For 
    Each strSwearWord In aSwearWords
       strCleanText 
    replace(strCleanTextstrSwearWord"[BEEP]")
    Next 
    /haven't tested this...

  3. #3
    Join Date
    Oct 2005
    Posts
    42
    hmmm im getting an error...

    Microsoft VBScript runtime error '800a01c3'

    Object not a collection

    thanks for your help so far!

  4. #4
    Ubik's Avatar
    Ubik is offline &lt;%= &quot;New Meja Hor&quot; %&gt;
    Join Date
    Nov 2005
    Location
    Earth
    Posts
    361
    Here you go, tested and works:

    PHP Code:
    <%
    strTextToBeCleaned "bleep you, you mother boper"
    strCleanText strTextToBeCleaned
    strSwearWordList
    ="beep, boop, bleep, bop, sheboing, ppppffft, bang"
    astrSwearWordList=split(strSwearWordList",")
    response.write "<p><ul>"
    For Each strSwearWord In astrSwearWordList
       strCleanText 
    replace(strCleanTexttrim(strSwearWord), "[BEEP]")
       
    response.write "<li>Checking '"&strSwearWord&"' - Changed to: "&strCleanText&"</li>"
    Next 
    response
    .write "</ul></p>"
    response.write "<p>"&strCleanText&"</p>"
    %> 
    Sorry, I has some variables out of place before.
    Last edited by Ubik; 01-20-2006 at 03:16 PM.

  5. #5
    Join Date
    Oct 2005
    Posts
    42
    hi ubik! that was great!

    sorry for the delayed reply...

    its working great btw!

    how would you be able to make it replace the words with *'s say, with the correct length of the word..

    say, the word SHABBA - 6 letters long, how can i make ****** - give a bit of a tease...lol, allways fun to guess what the word is lol

    thanks greatly!

  6. #6
    Ubik's Avatar
    Ubik is offline &lt;%= &quot;New Meja Hor&quot; %&gt;
    Join Date
    Nov 2005
    Location
    Earth
    Posts
    361
    Change:
    strCleanText = replace(strCleanText, trim(strSwearWord), "[BEEP]")

    To:
    PHP Code:
    strCleanText replace(strCleanTexttrim(strSwearWord), String(len(trim(strSwearWord)), "*")) 
    (tested, works)

  7. #7
    Join Date
    Oct 2005
    Posts
    42
    thats fantastic! thankyou!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles