fork download
  1. public class Main {
  2. public static void main(String[] args)
  3. {
  4. System.out.println(replaceVars("$myvar"));
  5. }
  6.  
  7. public static String replaceVars(String source)
  8. {
  9. String[][] varNames = new String[][]{new String[]{"myvar", "This is a variable"},
  10. new String[]{"anothervar", "This is another variable"},
  11. new String[]{"yetanothervar", "This is yet another variable"}};
  12. String result = source;
  13. System.out.println(result);
  14. for(String[] s : varNames) {
  15. result = result.replace("$" + s[0], s[1]);
  16. System.out.println(s[0]);
  17. System.out.println(s[1]);
  18. System.out.println(result);
  19. }
  20. System.out.println(result);
  21. return result;
  22. }
  23. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
$myvar
myvar
This is a variable
This is a variable
anothervar
This is another variable
This is a variable
yetanothervar
This is yet another variable
This is a variable
This is a variable
This is a variable