Reputation: 3628
In my properties file that I have for a mod I'm making for Minecraft I will need to have my properties file recognized certain words as being variables. These words will be contained like so: {variable name}
Here is an example of what might need to be parsed:
command01 = /ban {user} g {reason} //This is read into the variable command1 only taking the things after the equals sign
{user} would be defined in an input box in the GUI. {reason} would also be as well.
{User} would equal the variable user which would be a String {Reason} would equal the variable input1 which would be a String as well
Lets say the variable user holds the string "Fogest" and the input1 variable holds the string "He did xyz wrong".
I essentially need to retrieve that value from the GUI which is already done, and then replace {User} and {Reason} with what those variables are equal to in the GUI.
After all my rambling the question is how would I go about parsing the string command1 to find placeholders such as {user} and {reason} and replace them with what the corresponding variable holds.
I hope this isn't to confusing. If it just mention it in the comments and I will try and rephrase it.
Upvotes: 0
Views: 203
Reputation: 1006
It looks like what you question boils down to is some kind of string substitution. I think what you're looking for is something like this
String someString = "We went to the {location}.";
System.out.println(someString.replace("{location}", "store"));
Running this code produces
We went to the store.
Upvotes: 1