So, I’m trying to write a simple HTML server with processing (I know processing isn’t the best program to use, but I didn’t want to learn a new tool). The String my server’s supposed to send back is very long, so I wanted to split it up in multiple lines. Unfortunately, if you write something like
String return = (“first part
second part”);
processing throws an error and won’t compile.
Is there any way to split the same string into multiple lines?
1 Like
use \n to break the line, or use program
String text = "aaa|bbb|ccc";
void setup() { }
void draw() {}
void display() {
String lines[] = split(text,"|");
for(int i = 0; i < lines.length; i++) println(lines[i]);
}
or just do this:
you enter a String in format “line1|line2|line3|line4|…” and it will return “line1\nline2\nline3\nline4…”
That’s not what i was trying. i want to code the string using multiple lines in my code, but it should be sent as one ongoing line. when my string is 500 chars long, it gets hard to read when writing it in one line in the source code. So i want to to write the string using multiple lines. What would work is
String string = "text1";
string += "text2";
string += "text3";
but that seems laborious. I just thought there would be an easier approach
do something like
String a = "hello! This is the first segment!" + " This is the second segment!" + " The 3rd" + " 4th"
println(a);
//returns "hello! This is the first segment! This is the second segment! The 3rd 4th"
so you can do
String a = “aaaa” +
“bbbb” +
“cccc” +
“dddd”;
You could do something like this:
String value = "This " +
"is " +
"a " +
"string!";
It’s not pretty, but as far as I know the best way to do this in Java.
2 Likes