• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with MessageFormat  RSS feed

 
zahid zubair
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have some words to be printed in the console like so:



The thing is that all the 4 words may not be present. Say 'is' is not present, now the output should be:


I am using a pattern of PIPE delimeted values to get my job done.

The problem is I am getting the output as below:


i.e., I have EMPTY string with double quotes which I do not want in my resultant string.

My pattern reads something like this:


Can anyone please help me out so that double quotes(") won't come if string is EMPTY?


Thanks.
Zahid
 
Lorand Komaromi
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
zahid zubair wrote:My pattern reads something like this:


Please post the EXACT code, otherwise you'll confuse those who would like to help you!
 
zahid zubair
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code if in case it confuses you:
 
zahid zubair
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lorand,

I am still trying out to resolve this. Any ideas? Best practices?


Thanks,
Zahid
 
Rok Štelcer
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Replace the following line:
--> System.out.println(test);
with:
--> System.out.println(test.replaceAll("\"\"", ""));

This should do the trick.


Regards,
Rok
 
zahid zubair
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Rok!

Thank you. This should help me.

I feel like I am doing two string operations:

1. One for getting the formatted data
2. And another for replacing the data with ""

I am trying to resolve this into one operation. Thanks for your trick.


Regards,
Zahid
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!