1

I'm trying to present some values to the user with an order dictated by a "template", if we can call it like that.

An example: Let's imagine that we have some variables called "ID/Name/Surname" of a person. And then, we have a template string like

"{Id}, {Name}{Surname}"

So the string shown would be "1, Max Power". Or if we have a template string like

"{Surname}, {Name}"

We would have a result like "Power, Max".

What I have thought is doing it with nested replaces, like

Replace(Replace(Replace(templateString, "{Surname}", surname), "{Name}", name), "{Id}", id) //Being surname, name, and id variables

But there should be a better or better stylish way of doing that. How can I achieve this? Regular expressions?

Thanks.

xecollons
  • 536
  • 6
  • 22
  • 2
    I wonder if you are better off posting this on https://codereview.stackexchange.com/ – StayOnTarget Apr 22 '19 at 17:18
  • 2
    If you only have 3 parms, I think your approach is fine. Obviously this is less than ideal when you have many parms. You could also write this with 1 Replace statement per line. Or you could get fancy and throw RegEx into the mix like with this [example](https://stackoverflow.com/q/14534360/5162073). – Brian M Stafford Apr 22 '19 at 17:35

0 Answers0