我希望将fText
字符串值int b=3, a, c=10;
更改为:
int _sc_b=3, _sc_a, _sc_c=10;
通过使用数组元素内的文本。
我的代码:
var fText = "int b=3, a, c=10;";
sc_var_int_temp[0] = "a";
sc_var_int_temp[1] = "b";
sc_var_int_temp[2] = "c";
for( var vi=0; vi<sc_var_int_temp.length; vi++ ){
//how would i do the replacing?
}//for
目标:fText
价值将是 int _sc_b=3, _sc_a, _sc_c=10;
更新:尝试fText.replace(sc_var_int_temp[vi], "_sc_"+sc_var_int_temp[vi] );
但挂起系统^^
尽可能地,我打算使用循环进行替换
更新
我意识到当 fText 为时,我接受的答案将无法正常工作:
var fText = "int b=3,a ,c=10;";
//not really seperated by a single whitespace