none
replace variables in curly braces using regex in C# RRS feed

  • Question

  • Hi,

    I want to write a function in C#, which takes 2 arguments, one for string which must be raplaced, and the other the array of variables.

    I need to use regular expression for replacing and i should get smth like this if i call that function.

    string str = "{a} dkdkjgldk {ddd} dklfk {c}";

    some array, which has variables, named s = 10, ddd = 25, c = ani;

    str = function(str, that array);

    and my str will be "10 dkdkjgldk 25 dklfk ani";

    thanks in advance!

    Friday, February 8, 2013 9:49 AM

Answers

  • The solution depends on how the array of variables (including names and values) is defined and how simple ‘{‘ and ‘}’ (that do not denote a variable) are supposed to be represented in format string? Give some details.


    Friday, February 8, 2013 6:25 PM

All replies

  • Is this some assignment?

    There actually is this kind of an method in String class called Format.

    Friday, February 8, 2013 9:54 AM
  • Is this some assignment?

    There actually is this kind of an method in String class called Format.

    I need something like Format method, but using regex! And the differenc between my method and Format is that format has {0}, {1}... but i need the name of variables {a}, {ddd}...
    Friday, February 8, 2013 10:09 AM
  • The solution depends on how the array of variables (including names and values) is defined and how simple ‘{‘ and ‘}’ (that do not denote a variable) are supposed to be represented in format string? Give some details.


    Friday, February 8, 2013 6:25 PM