属性文件。解析某些文本。 (串)

时间:2012-02-22 01:53:29

标签: java parsing

在我的属性文件中,我有一个我为Minecraft制作的mod,我需要让我的属性文件将某些单词识别为变量。这些单词将包含如下:{variable name}

以下是可能需要解析的示例:

command01 = /ban {user} g {reason}  //This is read into the variable command1 only taking the things after the equals sign

{user}将在GUI的输入框中定义。 {reason}也是如此。

{User}将等于变量user,它将是String {Reason}将等于变量input1,它也是一个String

让我们说变量用户持有字符串“Fogest”,而input1变量包含字符串“He did xyz wrong”。

我基本上需要从已经完成的GUI中检索该值,然后用这些变量在GUI中等于的内容替换{User}和{Reason}。

毕竟我的漫无边际问题是如何解析字符串command1以找到占位符,例如{user}和{reason},并用相应的变量保存它们。

我希望这不要混淆。如果它只是在评论中提及它,我会尝试重新措辞。

1 个答案:

答案 0 :(得分:1)

看起来你的问题归结为某种字符串替换。我认为你正在寻找的东西是这样的

String someString = "We went to the {location}.";
System.out.println(someString.replace("{location}", "store"));

运行此代码会产生

We went to the store.