I have a string which contains several placeholder.. so I need to iterate over the String and replace name => mike, gender => male
String text = "Hi {#name} you are a {#gender}";
String[] values = {"Mike","Male"};
int count = -1;
Pattern pattern = Pattern.compile("(\\{)(#)(.+)(\\})");
Matcher matcher = pattern.matcher(text);
StringBuffer buffer = new StringBuffer();
while (matcher.find()) {
count++;
matcher.appendReplacement(buffer, values[count]);
}
matcher.appendTail(buffer);
System.out.println(buffer.toString());
It stops to: 'Hi mike'
I need the entire line to be replaced with new values
Thanks