문자열이 있는데 'C1과 C2 또는 C3 (~! @ # $ %) 및 C4 또는 C5'라고 말할 수 있습니다. ...... 이제 실제로 이것을 분할하여 배열에 보관했습니다. (inArray) 내가 원하는 조건을 할 때 조건이 경우 C3
에, 즉, 만족자바 스크립트에서 문자열 서식 지정
function removeCondition(condition,input){
//Condition is the String ie(C1 And C2) and input is the suffix no ie (3 for C3)
condition = condition.replace(new RegExp("\n","g")," ");
var inArray = condition.split(' ');
var conditionRemoved = false;
inArray.forEach(function(v,i,a){
if(v.indexOf("C"+input) > -1){
if(i+2 < a.length){
//some function i want
//inArray.splice(i,2);
}
else{
inArray.splice(i-1,2);
}
inArray.join(' ');
}
}
}//editor: added this bracket to balance the closing brackets
if()
위의 IE는 ... 지금은 다음 연산자와 함께 C3
(즉, 수 및/또는 수) 제거 할 그리고 사이에있는 모든 쓰레기 .. 위의 예를 들어 내 출력은 C1 AND C2 OR C4 OR C5
이어야합니다.
왜 'C3'을 제거 하시겠습니까? – Ejaz
thats 와트 요구 사항은 .. 그리고 그것은 C1, C2, C3 등등 수 있습니다 .. 제네릭 솔루션에 대한 m lukin – Kumar
아 .. 왜 thers는 ques에 투표 ... atleast 제공 .. 그래서 미래에 내가 수 있습니다. – Kumar