开发者

Formatted string parsing and updating

开发者 https://www.devze.com 2023-01-10 05:59 出处:网络
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.

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?


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号