Skip navigation
Currently Being Moderated

Newbie Problem

Mar 24, 2013 11:20 PM

Tags: #swf

I have been working on a extremely simple translator, with a template my friend has provided me with. Though I have quickly run into an issue, though it is the only issue, it is a severe one.


This is sections of my code;


bTranslate.onPress = function()


    var sInput = tIn.text; //Gets the text from the first text field.

    sInput = translate(sInput); //Goes through the translator.

    tOut.text = sInput; //Sets the second text field to the translated text.


function translate(sInput)


sInput = searchAndReplace(sInput, "hello", "achuta");

sInput = searchAndReplace(sInput, "a", "do");

return sInput;


function searchAndReplace(a, b, c) //Searches string a for b and replaces it with c


    tmp = a.split(b); //Splits a into an array of values where b is.

    a = tmp.join(c); //Joins them back together with c seperating them.

    return (a); //Returns the changed string.




There is more to it, but it's to long to post everything, regardless this leads to a good example.


So in my translator I would type Hello, which would then turn out the word, "Dochutdo" This is because the A's in Achuta are being converted by another word translation. I have been digging around but have not been able how to make this match case sensitive due to my lack of knowledge. I went around on the internet but couldn't find anything helpful in my case.


Does anyone know what I would have to change about this code in order to make all these words case sensitive to not effects letters individually within other words?

  • Currently Being Moderated
    Mar 25, 2013 5:49 AM   in reply to Mallind

    Your queston at the end of your description is not clear to me.  Can you give an example that demonstrates what you do/don't want.

    Mark as:
  • Currently Being Moderated
    Mar 25, 2013 10:01 AM   in reply to Mallind

    The best way to do that is with regular expressions.


    You can pass a regular expression to String.split instead of an actual String and you can make that case insensitive.


    Here is a good article:



    Let me know if you need further explanation.

    Mark as:
  • Currently Being Moderated
    Mar 25, 2013 10:30 AM   in reply to Mallind

    I don't see where the case comes into play in your problem.  If you want to test the whole word then do that and don't test for portions of it. 


    As2 does not support regular expressions in case you are trying to chase that down.

    Mark as:
  • Currently Being Moderated
    Mar 25, 2013 10:42 AM   in reply to Ned Murphy

    Ah, dang. I need to learn more about AS2 - I figured it would have had at least that much. Ignore my post then, haha!

    Mark as:
  • Currently Being Moderated
    Mar 25, 2013 12:10 PM   in reply to Mallind

    Yep, regular expressions are perfect for what you are trying to do - just too bad you can't use them. Unless you are able to use AS3?

    Mark as:
  • Currently Being Moderated
    Mar 25, 2013 4:48 PM   in reply to Mallind

    I still do not see where case fits into the scheme.  I also do not understand the logic behind what you are doing where you first translate to what you want and then you take what you translated and translate it again.  I think the problem you might be having is in your own reasoning of what the translator is trying to do.


    If hello gives you achuta, why do you then take achuta and translate it again... it is already translated  ?

    Mark as:
  • Currently Being Moderated
    Mar 26, 2013 6:01 AM   in reply to Mallind

    your problem lies in this line:


    tmp = a.split(b)


    what you want to do is separating the words from each other by using the the space betweeen them:


    tmp= a.split(" ");


    now you have each word in an array, now go throw this array and have a lookuptable for the corresponding translations,


    var language1 = ["hello","a"];

    var language2 = ["achuta","do"];


    function translateFromTo(_input,_language1,_language2){

      tmp = _input.split(" ");

    //this will be the text in your outputwindow

      result = "";

    //if you input "a hello a" this will give you an array of ["a","hello","a"]

    for (var i=0;i<tmp.length;i++){

    index1 = _language1.indexOf(tmp[i]);

    result += language2[index1]+" ";


    return result;



    trace(translateFromTo("a hello a",language1,language2));

    //do achuta do

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points