Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * replaces a placeholders on an arguments. <br>For example: <br>"parseArg(a, b);" <br>with a equal to <br><i>"lp user %arg_0%meta setprefix %arg_1%"</i><br>and
- * b is the array with elements: <br>"adffds", "fdsd" <br>will replace on <br><i>lp user adffds meta setprefix fdsd</i>
- * @param str - string to replace from
- * @param arg - arguments to which placeholders will replace
- * @return parse with replaced placeholders
- */
- private static String parseArg(String str, String... args)
- {
- if (args.length < 1) return str;
- boolean begin = false;
- int first = -1;
- int end = -1;
- int j = -1;
- String tmp = "";
- for (int i = 0; i< str.length(); i++)
- {
- if (str.charAt(i) == '%')
- {
- if (begin)
- {
- end = i;
- begin = false;
- if (tmp.equals(""))
- {
- str = str.subSequence(0, i-1).toString().concat(str.subSequence(i, str.length()).toString());
- i--;
- continue;
- }
- try
- {
- String[] s = tmp.split("_");
- if (s[0].equals("arg"))
- {
- j = Integer.parseInt(s[1]);
- String str1 = str.subSequence(0, first).toString();
- str1 = str1.concat(args[j]);
- str = str1.concat(str.subSequence(end+1, str.length()).toString());
- i = str1.length()-1;
- }
- }
- catch(ArrayIndexOutOfBoundsException e) {}
- continue;
- }
- begin = true;
- first = i;
- tmp = "";
- i++;
- }
- if (begin)
- {
- while (str.charAt(i) != '%')
- {
- tmp += str.charAt(i);
- i++;
- if (i >= str.length()) return str;
- }i--;
- }
- }
- return str;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement