0

So if you have the following string: "$(document).ready(function() {"

There are three open parentheses "("

I know there is the good 'ol string.replace(/(/g, "replacement_string"); way of doing things, but lets just say that doesn't exist for this question.

ここで、"(" を "?" に置き換える関数があるとします。文字列内の "(" ごとに関数を 1 回実行する方法はありますか?

4

1 に答える 1

0

を使用して文字列を分割できます

var theStringinQuestion="$(document).ready(function() {";
var strArr=theStringinQuestion.split("(");

for in次に、次のようにループを介して結果の配列を実行します。

var resultStr="";

for(substr in strArr){
  if(someCondition){ // where someCondition is your condition
    resultStr+=substr+"?"; 
  }else{
    resultStr+=substr+"("
  }
}
于 2010-07-04T02:18:38.233 に答える