How can I get the position of the substring that was read in by
getString(int resId, Object... formatArgs)?
For example I've got these resources
<string name="fruit">pear</string>
<string name="sentence">I like a <xliff:g id="fruit" example="apple">%s</xliff:g>.</string>
and read them in by
String fruit = getString(R.string.fruit); // = "pear"
String sentence = getString(R.string.sentence, fruit); // = "I like a pear."
I'd like to know where the word "pear" starts for example for underlining it. When the mentioned fruit is at the end of the sentence I can go for
int pos = sentence.length() - fruit.length() - 1;
but this breaks as soon as this changes (for example in a different language). I could search for fruit in sentence but this might break as soon as the same fruit gets mentioned twice for example.
Any ideas about how I can do this reliable? Sadly changing the implementation of resources and data parsing is not an option.