A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Foul Words

  1. #1
    Insomniac felicks's Avatar
    Join Date
    Oct 2002
    Location
    South London
    Posts
    213

    Foul Words

    Does anyone know of a way to search the contents of an input text box to find certain words? I want to identify and blank-out swear words that users might put into a form on my site.

    I am using Flash MX 2004, but have no real knowledge of the changes made in Actionscript 2.

    Hope you can help,
    Felix.
    Sleep is for people without imagination.

  2. #2
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    code:

    function replace(origStr, searchStr, replaceStr)
    {
    var tempStr = "";
    var startIndex = 0;
    if (searchStr == "") {
    return origStr;
    }
    if (origStr.indexOf(searchStr) != -1) {
    while ((searchIndex = origStr.indexOf(searchStr, startIndex)) != -1) {
    tempStr += origStr.substring(startIndex, searchIndex);
    tempStr += replaceStr;
    startIndex = searchIndex + searchStr.length;
    }
    return tempStr + origStr.substring(startIndex);
    } else {
    return origStr;
    }
    }
    var old_string = "this is the old string";
    var new_string = replace (old_string, "old", "new");
    trace(new_string); // this is the new string


    [taken from this post]

  3. #3
    Insomniac felicks's Avatar
    Join Date
    Oct 2002
    Location
    South London
    Posts
    213
    could you explain that code to me please? I'm afraid I'm one of theose people who likes to understand what i'm writing

    Thanks, Felix
    Sleep is for people without imagination.

  4. #4
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    The following script does the same thing, and perhaps can be explained more quickly, since it's shorter.

    code:

    str = "this is a line of hellish text";
    str = str.split('hell').join('heck');
    trace(str);



    str.split('hell') creates an array of strings using 'hell' as a delimiter. So all the parts of the string around the word 'hell' are retained. Then join('heck') joins those fragments back together, using 'heck' as a delimiter.

    So ultimately, it replaces any occurance of 'hell' with 'heck'. To use it with multiple words:

    str = str.split('hell').join('heck');
    str = str.split('tit').join('tat');
    str = str.split('potatoe').join('potato');

    etc.

    Now, having demonstrated it, I should mention that writing a good censorship script is harder than this. There are two problems: being too inclusive (as this script is) and not being inclusive enough. It is very difficult to find a balance between the two.

    This script is too inclusive. It replaces the word 'shell' with 'sheck'.

    You could fix that by modifying the script to require spaces before and after the word, but then you would also need to check if the string begins with hell or ends with hell, and what about punctuation?

    Finally, after you fix that problem, you'll find it's a simple matter for a user to type h.e.l.l. and get past it.

    Eventually, you will find that you need a more elaborate algorithm that breaks the string apart, removes all punctuation, keeps track of where the word boundaries are, accounts for upper/lower case, etc.

    Then, once you've done that, your users will start using other letters, like so:

    h.e.[.[.
    fvck
    c0cksvcker
    etc.

    Also, you'll find that you need to prevent it from turning "shell" to "sheck", (cause this makes users mad) but at the same time you probably DO want to turn "sfvck" into "sfudge" (cause "sfvck" also makes users mad), but if you use a uniform algorithm, there is no difference between the two.

    In general, you might find it easier to avoid censoring smaller words, like "tit" because they tend to be used as fragments of larger words, whereas "fvck" isn't a fragment of anything.
    "fvck" is unique in that way, however, many other swearwords (such as tit, ass, shiit) commonly occur as part of other words.

    Do you have a headache yet?

    Good luck...
    Last edited by jbum; 05-08-2004 at 01:44 PM.

  5. #5
    Member
    Join Date
    Jan 2004
    Posts
    67

    simple but super solution

    simple but super solution jbum!!

  6. #6
    Senior Member
    Join Date
    Aug 2005
    Posts
    170
    how do you make it work with a text feild like:
    Code:
    onClipEvent (enterFrame) {
    this.text_box.text =this.text_box.text.split('poo').join('faeces');
    }
    or something??

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center