c# - How to substitute place holders in a string with values -
given string
string command = "%ans[1]%*100/%ans[0]%" will replace %ans[1]% array[1] %ans[0]% array[2]
how substitute place holders in command values in array following result? should use regular expressions this?
and using regex.replace ?
"test2*100/test1"
you try using standard replace.
something like
string command = "%ans[1]%*100/%ans[0]%"; string[] array = new string[] { "test1", "test2" }; (int ireplace = 0; ireplace < array.length; ireplace++) command = command.replace(string.format("%ans[{0}]%", ireplace), array[ireplace]);
Comments
Post a Comment