# Making a line break instruction in a string work even though it's fetched from a csv file

**URL:** <https://discourse.processing.org/t/making-a-line-break-instruction-in-a-string-work-even-though-its-fetched-from-a-csv-file/28812>\
**Category:** Coding Questions\
**Created:** [March 24, 2021, 9:34pm UTC](https://discourse.processing.org/t/making-a-line-break-instruction-in-a-string-work-even-though-its-fetched-from-a-csv-file/28812 "2021-03-24T21:34:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bobolink](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bobolink/32/12555_2.png) [@Bobolink](https://discourse.processing.org/u/Bobolink)\
**Post date:** [March 24, 2021, 9:34pm UTC](https://discourse.processing.org/t/making-a-line-break-instruction-in-a-string-work-even-though-its-fetched-from-a-csv-file/28812/1 "2021-03-24T21:34:41Z")

</div>

I’m trying to print a string with a line break in it, where this string is fetched from a csv file.

When running the code below, typing in the string with the line break myself, everything works as expected:

```
import processing.pdf.*;
PFont f;

void setup() 
{  
    size(1000,1000, PDF, "Output.pdf");
    background(255);
    f = createFont("Arial",16);
}

void draw() 
{  
    Table table;
    table = loadTable("Input.csv", "header");
    for (int i = 0; i < table.getRowCount(); i = i + 1)
    {    
        textFont(f);
        fill(0);
        text("First line.\nSecond line.", 100, 100); // I'm typing in the string myself here.
    }
    exit();
}

```

However, when running this other piece of code below, fetching the string with the line break from a csv file, the line break instructions, “\n”, is printed and no line break occurs:

```
import processing.pdf.*;
PFont f;

void setup() 
{  
    size(1000,1000, PDF, "Output.pdf");
    background(255);
    f = createFont("Arial",16);
}

void draw() 
{  
    Table table;
    table = loadTable("Input.csv", "header");
    for (int i = 0; i < table.getRowCount(); i = i + 1)
    {    
        textFont(f);
        fill(0);
        text(table.getString(i,"Column_1"), 100, 100); // I'm fetching the string from the csv file here.
    }
    exit();
}

```

This is what the csv file looks like:

```
"Column_1"
"First line.\nSecond line."
```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 24, 2021, 9:45pm UTC](https://discourse.processing.org/t/making-a-line-break-instruction-in-a-string-work-even-though-its-fetched-from-a-csv-file/28812/2 "2021-03-24T21:45:20Z")

</div>

Interesting!

Can you give an example line from the csv?

Presumably the Strings in it must be enclosed in " and "

---

<div class="post-metadata">

**Author:** ![Bobolink](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bobolink/32/12555_2.png) [@Bobolink](https://discourse.processing.org/u/Bobolink)\
**Post date:** [March 24, 2021, 9:48pm UTC](https://discourse.processing.org/t/making-a-line-break-instruction-in-a-string-work-even-though-its-fetched-from-a-csv-file/28812/3 "2021-03-24T21:48:51Z")

</div>

Sorry, I forgot to add the csv file. I’ve added it at the end of my post. As you can see, the string is enclosed in quotes.

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [March 24, 2021, 11:12pm UTC](https://discourse.processing.org/t/making-a-line-break-instruction-in-a-string-work-even-though-its-fetched-from-a-csv-file/28812/4 "2021-03-24T23:12:15Z")

</div>

Hi @Bobolink ,

Welcome to the forum! 😉

I found the issue, I made a small code to show the string as an array of characters :

```java
String firstRow = table.getString(0, "Column_1");
  
print("[");
for (int i = 0; i < firstRow.length(); i++) {
  print("'" + firstRow.charAt(i) + "'");
  if (i < firstRow.length() - 1) print(", ");
}
print("]");

```

Which gives :

```auto
['F', 'i', 'r', 's', 't', ' ', 'l', 'i', 'n', 'e', '.', '\', 'n', 'S', 'e', 'c', 'o', 'n', 'd', ' ', 'l', 'i', 'n', 'e', '.']

```

As you can see, the line break is considered as two separate characters therefore they are drawn when using the `text()` function.

Here is the solution :

> <https://stackoverflow.com/questions/566052/can-you-encode-cr-lf-in-into-csv-files>

You need to put a real line break inside the quotes :

```auto
"Column_1"
"First line.
Second line."

```

---

<div class="post-metadata">

**Author:** ![Bobolink](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bobolink/32/12555_2.png) [@Bobolink](https://discourse.processing.org/u/Bobolink)\
**Post date:** [March 24, 2021, 11:43pm UTC](https://discourse.processing.org/t/making-a-line-break-instruction-in-a-string-work-even-though-its-fetched-from-a-csv-file/28812/5 "2021-03-24T23:43:42Z")

</div>

Thanks, that solved it! 🙂 I still don’t fully understand why the string which is typed in manually wasn’t treated the same way, but that’s not that important now I guess.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 25, 2021, 8:23am UTC](https://discourse.processing.org/t/making-a-line-break-instruction-in-a-string-work-even-though-its-fetched-from-a-csv-file/28812/6 "2021-03-25T08:23:44Z")

</div>

> [@josephh](#):
>
> You need to put a real line break inside the quotes :

Interesting.

But I don’t think I can do this in the normal Windows Notepad Editor?

Can I do it in Excel? It’s Alt-Return or something.

So which editor to use?

When the csv is made from another Sketch it’s different maybe
