I have a string of following format
Select * where {{0} rdfs:label "Aruba" } limit 10
Now I would like to replace {0} with some new text, but the problem is message format is unable to parse the string due to the first curly bracket. I know if i use '{' it would escape it, but the problem is I have loads of such type of string and I cannot manually add single quotes before and after the curly bracket. Even if I write a function to do this, it would escape the curly brackets for the placeholder {0} as well.
Is their a better alternative to message format, something like ruby string interpolation. I just want a way to write a string template where i can replace certain parts with new string
{
}
characters) but which contains MessageFormat style arguments. The answers posted here, including your own, will likely be good enough to address your use-case, but I have to ask how did these malformed strings come to be in the first place? Whatever person or process created them should be expected to provide valid MessageFormat strings (perhaps you should provide a validator); that is a far more robust solution than attempting to modify the strings after the fact. – Annulus