用java代码替换多个字符串

时间:2013-04-22 14:10:00

标签: java string text merge concatenation

我需要替换:

myVariable = "sample string is long " +
  "so I put rest of it in 2nd line." +
  " And sometimes in 3rd and so on";

使用:

myVariable = "sample string is long so I put rest of it in 2nd line. And sometimes in 3rd and so on";

其他问题:如何合并上面的实体我在串联链中有其他变量吗?

myVar = "The number of the beast is " + numberOfTheBeast + " !!! So I said";

我想做的是将其改为单个字符串,其中包含params。

1 个答案:

答案 0 :(得分:1)

我不是正规表达大师,但这三个正则表达式替换应该可以解决问题。大多数IDE都具有正则表达式替换功能。

Replace:     With:
\s*\+\s*\n    +   (space, plus, space)
"\s*\+\s*"   nothing
\s*\+\s*      +   (space, plus, space)

如果你在Windows上,你可能必须使用\ s * + \ s * \ r \ n作为第一个正则表达式。