# Write a string in multiple code lines

**URL:** <https://discourse.processing.org/t/write-a-string-in-multiple-code-lines/27196>\
**Category:** Coding Questions\
**Created:** [January 19, 2021, 11:32am UTC](https://discourse.processing.org/t/write-a-string-in-multiple-code-lines/27196 "2021-01-19T11:32:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JonasAvory1](https://avatars.discourse-cdn.com/v4/letter/j/87869e/32.png) [@JonasAvory1](https://discourse.processing.org/u/JonasAvory1)\
**Post date:** [January 19, 2021, 11:32am UTC](https://discourse.processing.org/t/write-a-string-in-multiple-code-lines/27196/1 "2021-01-19T11:32:49Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [January 19, 2021, 12:37pm UTC](https://discourse.processing.org/t/write-a-string-in-multiple-code-lines/27196/2 "2021-01-19T12:37:20Z")

</div>

use \n to break the line, or use program  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/83dce56e132f622f20d2aca823be70e4e7b39573.png)

```auto
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]);
}

```

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/c3e3c10e77c4cefd6f98de75fc5ab60760837a8d.png)

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [January 19, 2021, 12:48pm UTC](https://discourse.processing.org/t/write-a-string-in-multiple-code-lines/27196/3 "2021-01-19T12:48:59Z")

</div>

or just do this:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/a6a18aa2b59dd59a72253a0f09fd04b6c2d146d0.png)  
you enter a String in format “line1|line2|line3|line4|…” and it will return “line1\nline2\nline3\nline4…”

---

<div class="post-metadata">

**Author:** ![JonasAvory1](https://avatars.discourse-cdn.com/v4/letter/j/87869e/32.png) [@JonasAvory1](https://discourse.processing.org/u/JonasAvory1)\
**Post date:** [January 19, 2021, 1:06pm UTC](https://discourse.processing.org/t/write-a-string-in-multiple-code-lines/27196/4 "2021-01-19T13:06:44Z")

</div>

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

```auto
String string = "text1";
string += "text2";
string += "text3";

```

but that seems laborious. I just thought there would be an easier approach

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [January 19, 2021, 1:14pm UTC](https://discourse.processing.org/t/write-a-string-in-multiple-code-lines/27196/5 "2021-01-19T13:14:50Z")

</div>

do something like

```auto
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”;

---

<div class="post-metadata">

**Author:** ![Schred](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/schred/32/13146_2.png) [@Schred](https://discourse.processing.org/u/Schred)\
**Post date:** [January 19, 2021, 1:15pm UTC](https://discourse.processing.org/t/write-a-string-in-multiple-code-lines/27196/6 "2021-01-19T13:15:48Z")

</div>

You could do something like this:

```auto
String value = "This " +
               "is " +
               "a " + 
               "string!";

```

It’s not pretty, but as far as I know the best way to do this in Java.
