I have the following information
String templateString = "I am %NAME% and I live in %PLACE%";
String inputString = "I am John Doe and I live in New York";
I need to write a function which will take in the above 2 strings and return a HashMap of pairs.
HashMap<String,String> parseInputFromTemplate(templateString, inputString) {
// Magic
return result;
}
The result will have
%NAME% (key) , John Doe (value) %PLACE% (key) , New York (value)
Any pointers would be appreciated.
You can use regular expressions to extract what you need. Alternatively you can use the split() method to split on "%". Every other string in the resulting array would be a template var. The others would be the static strings to discard in the inputString.