I am currently creating a configuration file that will replace this line with several variables, it is difficult for me to explain this, so it might be better to show you what I mean:
The following method will be used with String: Hello ~ and is welcomed in ~!
private static String REPLACE_CHAR = "~"; public static String parse(String key, String... inputs) { int cache = matchCache.get(key, -1); String value = customConfig.getString(key); if (cache == -1) { cache = StringUtils.countMatches(value, REPLACE_CHAR); matchCache.put(key, cache); } for (int i = 0; i < cache; i++) { value = value.replaceFirst(REPLACE_CHAR, inputs[i]); } return value; }
what would be a quick way to replace ~ with the first input, then go to the second ~ and so on ...
Now the main reason I didn’t use another user's code: Ideally, I would like to create a list of various replaceable characters, which, in turn, will replace the variable automatically, so in this code I can not give it any inputs, but it will check a list for interchangeable characters and execute a method such as getYourName () Does this list need to be checked every time so that the template can still be compiled?
I do this to learn as much as for effectiveness, I lack the ability when it comes to regular expression!
source share