\"/home/john/bin;/dev/null\"" />
开发者

Expand env variables in String

Is there some java utility, which will expand ~ and env. variables in a string?

Like "~/bin;${MY_PATH}" -> "/home/john/bin;/dev/null"

Th开发者_开发知识库ank you


Basically, you want to do String interpolation with environment variables and expand home directories. I don't know of an easy way to do the latter, but if you use Spring to do your set-up you can use it's PropertyPlaceholderConfigurer to replace placeholders in strings.

By default, environment variables are included in the set of placeholder replacements.

UPDATE: As this is from the user, you can still make use of Spring helper classes:

String stringToBeInterpolated = ....;
Properties properties = System.getProperties();
PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("${","}");
String interpolatedValue = helper.replacePlaceholders(stringToBeInterpolated , properties);

This doesn't help with the ~, but at that point I'd assume you can do a fairly simple string replace operation.


You can give the full path for the bin folder and use System.getProperty("EVN_PROP_HERE")

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜