4

I have different Strings like this

" Hello *|USERNAME|*,

  to activate your account please click here *|ACTIVATION_LINK|*
"

another example

" Hello,

  to reset your password please click here *|RESET_URL|*
"

for the first String I would have a List of key values like this

((USERNAME, Nick),(ACTIVATION_URL, http://whateverhost/activation_url))

for the second

((RESET_URL, http://whateverhost/reset_url))

I want to replace the strings with the List of Key/Values, the List can have a variable length and the occurrences of the keys in the String may be multiple

I tried something like this

mapKeyValues.map { x => bodyString.replaceAll(x._1, x._2) }

But the problem is I get a new List where each row has the replacement of one row of the Key/Values

Is there a way to do this?

1
  • Please look at some templating engines, for example Twirl Commented Apr 24, 2016 at 17:09

1 Answer 1

6

You can do it using foldLeft:

mapKeyValues
  .foldLeft (bodyString) {case (acc,(key,value))=>acc.replaceAll(key, value)}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.