Do you really need as incoming parameter that "array" ? If not, that you can implement as easy as it is ..
private static String replaceVarByVal(String toReplace,String var,String val){
return toReplace.replace(var, val);
}
(You can easy modify that to incom params arrays, but better should be eg. Map- key variable, value new value of the "placeholder" - $var)
Arrays variant:
private static String replaceVarByVal(String toReplace,String[] var,String[] val){
String toRet = toReplace;
//arrays logic problem
if(var.length != val.length){
return null;
}else{
for (int i = 0; i < var.length; i++) {
toRet = toRet.replace(var[i], val[i]);
}
}
return toRet;
}
Better variant with map:
private static String replaceVarByVal(String toReplace,Map<String, String> paramValsMap){
String toRet = toReplace;
for (Map.Entry<String, String> entry : paramValsMap.entrySet())
{
toRet=toRet.replace(entry.getKey(), entry.getValue());
}
return toRet;
}
(And that can be used universally for anything)