cancel
Showing results for 
Search instead for 
Did you mean: 

Insert new lines into a String

Former Member
0 Kudos

Hi,

I want insert different lines into a String, for example, I want tho show a String like this:

Line 1

Line 2

Line 3...

I've wrote the next code: String lines = "Line 1" + "\n" + "Line 2" + "\n"...

myrow.addElement(lines).

When I show my model, it show so: Line1 Line2 Line3..., but when I open a pdf file with the model, it show so:

Line 1

Line 2

Line 3

Why in my model show: Line 1 Line 2.. but in pdf show in differents lines?

How I can show in muy model in differents lines?

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

> I've wrote the next code: String lines = "Line 1" + "\n" + "Line 2" + "\n"...

> myrow.addElement(lines).

> When I show my model, it show so: Line1 Line2 Line3...

Like the others, I don't know exactly how you "show your model", but could it be you are attempting to display it in a browser with HTML? In that case, line breaks are (normally) not interpreted; you could use

String linesHTML = "Line 1" + "<br/>" + "Line 2" + "<br/>" + ...

.

(Of course, this will not work in PDF format; you would have to use different Strings for the two formats).

Regards,

Jens

Former Member
0 Kudos

Try this

char lf = 0X0A;

char cr = 0X0D;

String lines = Line1lfcrLine2lfcrLine3;

For better performance, I advise to use the append operator (Stringbuffer) instead of the + operator (String).

StringBuffer sb = new StringBuffer();

sb.append(lf).append(cr).append(Line1).etc etc

The result is

sb.toString();

good luck, Roelof

Former Member
0 Kudos

Try this

public static String newline = System.getProperty("line.separator");

StringBuffer buff = new StringBuffer();

buff.append(newline).append(Line1).append(newline).append(Line2)..

String result = buff.toString();

Regards,

Puspendu

Former Member
0 Kudos

Hi,

can you just describe a bit closer which coding you are using (especially the coding for myrow)? Further some more information concerning the model might be helpful. Have you tried a coding like this:

"Line 1\n" + "Line 2\n" + ... If so what happens?

Brgds,

Marcel