Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a LineBreak (\n) to a String.format with fixed String as format?

Tags:

java

string

In the code below, message is a final String that have a \n inside it, and it doesn't work.

message = format = "Blah %d Blah Blah \nBlah Blah %s Blah"
interventionSize = number
UserID = String
String.format(Dic.message,interventionSize,userID)

How can I make the line break in this case, cannot find an answer.

BTW, I cannot use any kind of framework or external jar to do that (old code) have to use Plain Old Java.

like image 436
Cristiano Fontes Avatar asked Feb 09 '11 13:02

Cristiano Fontes


1 Answers

Having \n in a format string is just fine.

Perhaps you should try a platform specific new-line. With format strings you can use %n.

That is, try the following:

String.format(Dic.message.replace("\\n", "%n"), interventionSize, userId);
like image 68
aioobe Avatar answered Oct 21 '22 20:10

aioobe