A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Find certain words in a text field

  1. #1
    the cheesy child bounceboy's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    323

    Find certain words in a text field

    Hi everybody!

    I have had alot of ideas for a chatroom but there's a few problems... i want to make sure certain words can't be said!

    I don't want swearing, but I would like to just change the swearing to other things so that the message will still be sent and not just be annoying.

    eg: F*** can be fudge
    S*** can be Shoot

    etc.

    please tell me, and i don't want to have to be using PHP!!!

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    does this method work for you ?
    on stage -
    input textfield - instance name - inp
    button - instance name - btn
    PHP Code:
    exclWords = ["f*ck","sh*t","a*s"]; // fill in the blanks 
    inclWords = ["fudge","shoot","uss"];

    btn.onRelease = function(){
    findWords(inp.text);
    };

    function 
    findWords(str){
    temp str.split(" ");
    for(var 
    v=0;v!=exclWords.length;v++){
    for(var 
    w=0;w!=temp.length;w++){
    if(
    temp[w] == exclWords[v]){
    str str.split(temp[w]).join(inclWords[v]);
    }
    }
    }
    sendTxt(str);
    };

    function 
    sendTxt(newStr){
    trace(newStr);
    }; 

  3. #3
    the cheesy child bounceboy's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    323
    thank you very much a_modified_dog

    unless you are doing something, would you mind explaining the script?

    i am new to arrays.

  4. #4
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    excluded words in array - exclWords
    replacement words in array - inclWords

    on button press -
    send inp.text to function - findWords(inp.text);
    split inp.text to array - temp
    cycle thro' temp comparing against exclWords
    if an exclWord is found, replace it with inclWord
    when complete, send the new string to function sendTxt and display in output window.

  5. #5
    the cheesy child bounceboy's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    323
    thank u once again!

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