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

Popular posts from this blog

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -

openssl - Load PKCS#8 binary key into Ruby -