Here you can find the source of substituteEnvironmentVariables(String str, String prefix, String suffix)
public static String substituteEnvironmentVariables(String str, String prefix, String suffix)
//package com.java2s; //License from project: Open Source License public class Main { public static String substituteEnvironmentVariables(String str, String prefix, String suffix) { StringBuilder buffer = new StringBuilder(str); int prefixLength = prefix.length(); int index = 0; while (index < buffer.length()) { index = buffer.indexOf(prefix, index); if (index < 0) break; index += prefixLength;//w ww . j a v a2 s .c o m int startIndex = index; index = buffer.indexOf(suffix, index); if (index < 0) index = startIndex; else { String value = null; if (index > startIndex) { try { value = System.getenv(buffer.substring(startIndex, index)); } catch (SecurityException e) { // ignore } } startIndex -= prefixLength; if (value == null) value = ""; buffer.replace(startIndex, index + suffix.length(), value); index = startIndex + value.length(); } } return buffer.toString(); } }