开发者

left open parenthesis messes up my string buffer

I got a string buffer which I then put into a bean and call on a webpage with JSTL. I want it to output something like 10/10/1987 (23 years). The first example doesn't return anything and the second example does.

patAge.append(" ")
      .append("(")
开发者_高级运维      .append(patientDetails.getAge())
      .append(" ")
      .append(bpt.get("BPT_YRS"))
      .append(")");

output: 10/10/1987

patAge.append(" ")
      .append("{")
      .append(patientDetails.getAge())
      .append(" ")
      .append(bpt.get("BPT_YRS"))
      .append(")");

output: 10/10/1987 {23 years)

patAge.append(" ")
      .append(patientDetails.getAge())
      .append(" ")
      .append(bpt.get("BPT_YRS"))
      .append(")");

output: 10/10/1987 23 years)

It seems that the left open parenthesis causes that it doesn't work.


For readable code, I recommend to switch to MessageFormat.

This is the default example:

Object[] arguments = {
         new Integer(7),
         new Date(System.currentTimeMillis()),
         "a disturbance in the Force"
     };

String result = MessageFormat.format(
         "At {1,time} on {1,date}, there was {2} on planet {0,number,integer}.",
         arguments);

output: At 12:30 PM on Jul 3, 2053, there was a disturbance in the Force on planet 7.

So you separate the variables from your message.


It looks like there is an synax error in your fist statement: the append((") (2. append) looks strange.

I belive it should be:append("(") (one more ")

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜