2016-07-04 4 views
0

죄송합니다. 저는 프랑스어로 영어로 몇 마디 밖에 안됩니다. 나는 어쩌면 바보 같은 질문이 있습니다2 또는 + 변수를 할당하는 방법

원래 코드 : var test = { commandChar : "!", };

for (i = 0; i < commands.length; i++) { 
    if (commands[i].hasOwnProperty('alt')) { 
     for (j = 0; j < commands[i].alt.length; j++) { 
      if ((index = text.toLowerCase().search(new RegExp("^\\" + test.commandChar + commands[i].alt[j].toLowerCase() + "\\b"))) >= 0) { 
       break; 
      } 
     } 
    } 

    if (index < 0) { 
     index = text.toLowerCase().search("^\\" + "[" + test.commandChar + ",@#]" + commands[i].name.toLowerCase() + "\\b"); 
    } 

    if (index > -1) { 
     var command = text.slice(index).split(" "); 
     if (!(commands[i].op || commands[i].elevated) || host || mod || authorised) { 
      if (!(commands[i].mod) || host || mod) { 
       commands[i].command(command, user); 
      } 
     } 
     else { 
      //sendChat("You have to be authorised to use " + commands[i].name + "."); 
     } 
     break; 
    } 
} 

이이 작은 로봇은, 예를 들어. commandChar : "!"인 경우. ! 도와주세요.하지만/도와주세요. 많은 symbole을 가진이 commandChar을 사용하고 싶습니다. 처럼 commandChar : "!", "/"; 사용

! 도와/도움말

내가 덕분에, 그것은해야하거나 내가 제대로 자신을 표현하지 않은 경우 배열 또는 RegExpr는

죄송 그것을 복잡하게 생각

답변

0

그것을 할 수있는 많은 방법이있다하지만, 다음은 빠른 답변입니다.

function isValidCommandChar(str) { 
    return "!/.".indexOf(str.charAt(0)) > -1; 
} 

isValidCommandChar("!help"); // true 
isValidCommandChar("#help"); // false 
isValidCommandChar("/help"); // true 
isValidCommandChar(".help"); // true 
+0

감사합니다. 시험해 보겠습니다. – Macasun

+0

문제 없으나 대답을 수락대로 표시하십시오. :) – Lifz

관련 문제