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