Precondition
我有一个字符串,如下所示:
代码如下所示:
Map<String, Object> textParameters=new Hashmap<String,String>();
textParameters.put("firstParameter", "Hello World");
StringSubstitutor substitutor = new StringSubstitutor(textParameters);
String replacedText = substitutor.replace(myText)
替换文本为:
The problem
在替换的字符串中,没有提供secondParameter
参数,因此出于这个原因,已打印出声明.
What I want to achieve?
如果一个参数没有映射,那么我想用一个空字符串替换它来隐藏它的声明.
在这个例子中,我想实现这个目标:This is a foo text containing Hello World and
Question
如何使用StringUtils/Stringbuilder实现上述结果?我应该改用regex吗?