In 1.3 and below, there is really only `StringBuffer` and `StringTokenizer` (and a `replace` method to replace a single char by another one) for String manipulation. 1.4 brought Regex and `replaceAll` and makes it much more pleasurable.

As `getenv` only works in 1.5 and above anyway, I'd probably hack up some very stubby implementation for 1.4 and below (that just knows enough variables to get the `shell` command working), and use proper replace in 1.5 and above.

Using `StringTokenizer` and `StringBuffer` to replace out some characters from a String is not hard either (while hasMoreTokens, append nextToken), though, but tedious to write (and I can understand it feels for you like it feels me me if I have to use `strtok` and `strstr`in plain C...).

BTW: https://github.com/rapid7/meterpreter/blob/3ffef7f4d9b16dd3869ea806fa8c9b4334f94923/source/extensions/stdapi/server/sys/config/config.c#L61 does not look less hackish to me ...