I have checked few of the existing questions but could not find any matching case.
I have a index.jsp page with ten variables declared and value assigned , an user from UI input text box can provide any value along with our existing variable with '@' prefix
eg 1: userinput = a=@useremail&b=c&d=@city
expected output : a=test@email&b=c&d=newyork
eg 2: userinput = a=b&c=@firstname
expected output : a=b&c=mark
with variable declared as below
String useremail = "test@email.com"
String lastname = "tony"
String firstname = "mark"
String city = "newyork"
String country = "US"
Now I need to replace these variables with actual values , if have tried with below snippet
if (inputText.contains("@")) {
if (inputText.contains("@useremail"))
inputText = inputText.replace("@useremail",useremail);
else if (inputText.contains("@lastname"))
inputText = inputText.replace("@lastname", lastname);
else if (inputText.contains("@firstname"))
inputText = inputText.replace("@firstname", firstname);
//need to check for all variables
}
I find trouble in using switch case as the value is a substring of the userinput, please help me to execute the case with best practices.
Thank you.