substitute

  • Thread starter Thread starter GS
  • Start date Start date
G

GS

what is that best way to substitute in string something like ${somename}
with its corresponding value. procedural wise, stepping through each found
match and replace accordingly

One way in pseudo code:

string str4subs = "something is ${param1}${param2} some other things
${exprk} whatever"; // in real life it may be a lot longer and with more
substitution required
Regex myregex = new Regex("(\$\{\w\}, Regexoptions.ignoreWhitespace|
Regexoptions.multiLine |Regexoptions.ignorecase)";
Match myMatch = new myregex.Match(str4subs)

// oops, I am stuck here as to how to use match group or capture to replace
with the corresponding value

// don't want to iterate all possible pair
I need help here
 
what is that best way to substitute in string something like ${somename}
with its corresponding value. procedural wise, stepping through each found
match and replace accordingly

One way in pseudo code:

string str4subs = "something is ${param1}${param2} some other things
${exprk} whatever"; // in real life it may be a lot longer and with more
substitution required
Regex myregex = new Regex("(\$\{\w\}, Regexoptions.ignoreWhitespace|
Regexoptions.multiLine |Regexoptions.ignorecase)";
Match myMatch = new myregex.Match(str4subs)

// oops, I am stuck here as to how to use match group or capture to replace
with the corresponding value

// don't want to iterate all possible pair
I need help here

It it's a string you might use String.Replace() ? I have no idea about
the performance of it, though.

- Dan
 
Sine the variable names and values are not fixed but from a database table,
I am inclined to use a dataset with match evaluator, what do you think?

I am now look at using match evaluator. If I have the
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top