Monday, 19 August 2013

vb.net string - replace placeholder tokens efficiently

vb.net string - replace placeholder tokens efficiently

I'm just looking for some ideas with a little problem. I've a string
that's a template for a message, for example:
Dear [[Guest.FirstName]],
We hope your are looking forward to your holiday in [[Booking.ResortName]]
My current system for replacing the spaceholder tokens (e.g.
[[Guest.FirstName]]) is very inefficient, there's loops inside loops and
it takes for too long.
What I'm looking for is a way that would go through the string until it
finds [[something]], then replace that [[something]] with it's real value,
then continue on through the string.
Please note to replace [[something]] then I need to have access to the
space holder (i.e. i need to know if it's [[Guest.FirstName]] or
[[Booking.ResortName]]).
Any suggestions for an efficient way to achieve this would be very much
appreciated, I feel it should be fairly straightforward but everything I
can think of ends up with loops inside loops again.
Thanks!
Phil.

No comments:

Post a Comment