0
var jtj_code_lines = []; // this array will hold all the jtj codes line

var JTJ = function(j){
     j = j.replace(" ",""); 
   jtj_code_lines = j.split(';'); // splitting all the lines seperated from  ;

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

       if(jtj_code_lines[i].charAt(0) === '*'){ // * means that the following word is the name of a method that will perform some action
           var q1 =  jtj_code_lines[i].replace('*', ''),
           q1_pos_1 = q1.indexOf('['); // find the position of the keyword [
           var q1_funcname = q1.slice(0, q1_pos_1); // it find the name of that perticular function 

           if(q1_funcname === "Message"){  // this checks weather the function name is message
               var q1_pos_2 = q1.indexOf(']'), // this ifnds the position of keyword ]
               q1_func_value = q1.slice(q1_pos_1+1, q1_pos_2);  // this finds what is written inside [] and accepts as the value of Message 

               alert(q1_func_value);
           }else{

           }

       }
   }
};

so the above function is pretty simple it finds the specific text written in the braces, i mean that if you write :

JTJ('*Message[hi];')

then it will alert hi and this is quit simple and this is alerting as expected but the problem is coming that if any * is after white space then that perticular thing is not being alerted, so the following have the same condition,*Message[go ]; starts with whitespace so it is not being alerted :

JTJ('*Message[sanmveg];*Message[saini]; *Message[go ];')  

but i have a this line j = j.replace(" ",""); to remove all the white spaces, then why it is not working? is there any other way to do this?

thanks.

anni
  • 290
  • 1
  • 3
  • 15

1 Answers1

1
Fix: j = j.replace(/\s/gi,"");

this would remove all " " with "", in short it would act as replaceAll. Before it was just replacing first matched " " with "".

vinayakj
  • 5,591
  • 3
  • 28
  • 48