views:

18

answers:

1

I need to replace specialy marked place holders in string with values. Similar to what string.Format does, but in a bit more advance way.

For instance: input string: "Welcome to {Binding Path=@city}!" Value for @city is "Boston" Output string should be "Welcome to Boston!".

I can successfully parse input string with regex and get the values. But to update the string I'm just using string.Replace. I'm currious if there's a better way to handle updates for such scenarious?

+1  A: 

You could use the Regex.Replace method, but you really only need it if you see having multiple spots to replace of one match (EX: multiple {Binding Path-@city} in one string).

Tony Abrams
If I'll have multiple patterns to replace with diffrent values, Regex.Replace won't work. For instance if input is "Welcome {Binding Path=@name} to {Binding Path=@city}!" this won't work, as will replace all patterns with same value.
Andrii V
Correct, I was talking about times where you have multiple occurrences of the same string to replace. The match pattern would have to be specific in this case.
Tony Abrams