# Question about loadstrings() function

**URL:** https://discourse.processing.org/t/question-about-loadstrings-function/20824
**Category:** Coding Questions
**Created:** [May 13, 2020, 1:43pm UTC](https://discourse.processing.org/t/question-about-loadstrings-function/20824 "2020-05-13T13:43:12Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![David](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/david/32/8853_2.png) [@David](https://discourse.processing.org/u/David)
#### Post date: [May 13, 2020, 1:43pm UTC](https://discourse.processing.org/t/question-about-loadstrings-function/20824/1 "2020-05-13T13:43:12Z")

</div>

Hi!

Is it expected behaviour for the ‘loadstrings()’ function to skip blank or empty lines in Processing 3? The documentation doesn’t mention this, but that seems to be the case. I’m loading a small text file which has some empty lines (not even spaces), and it seems to be skipping them.

https://processing.org/reference/loadStrings\_.html

Thanks.

---

<div class="post-metadata">

### Author: ![tony](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tony/32/949_2.png) [@tony](https://discourse.processing.org/u/tony)
#### Post date: [May 14, 2020, 1:02am UTC](https://discourse.processing.org/t/question-about-loadstrings-function/20824/2 "2020-05-14T01:02:28Z")

</div>

Good question. I believe this might be expected behavior. After some digging, it looks like loadStrings() utilizes a BufferedReader:

> <https://github.com/processing/processing/blob/349f413a3fb63a75e0b096097a5b0ba7f5565198/core/src/processing/core/PApplet.java#L7503>

Inside, we can see `readline()` being called, and [according to the docs](https://docs.oracle.com/javase/8/docs/api/java/io/BufferedReader.html#readLine--):

> Returns:  
> A String containing the contents of the line, _ **not including any line-termination characters** _, or null if the end of the stream has been reached

In short, it’s tossing the empty lines.

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [May 14, 2020, 4:11am UTC](https://discourse.processing.org/t/question-about-loadstrings-function/20824/3 "2020-05-14T04:11:15Z")

</div>

> [@tony](#):
>
> In short, it’s tossing the empty lines.

It is tossing the line terminators, but it is still indexing the lines in the array – it doesn’t “skip” them or “toss” them completely.

Given a five line text file, foo.txt:

> foo
> 
> bar
> 
> baz

This code:

```auto
String[] strs = loadStrings("foo.txt");
for(int i=0; i<strs.length; i++){
  println(i, strs[i]);
}

```

outputs:

> 0 foo  
> 1  
> 2 bar  
> 3  
> 4 baz

---

<div class="post-metadata">

### Author: ![David](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/david/32/8853_2.png) [@David](https://discourse.processing.org/u/David)
#### Post date: [May 14, 2020, 10:06am UTC](https://discourse.processing.org/t/question-about-loadstrings-function/20824/4 "2020-05-14T10:06:22Z")

</div>

Thanks. I should have done more investigation before posting. I found the problem, it has nothing to do with the loadStrings() function, but with another function that was using the array of strings. Seems it skips empty lines.

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [May 14, 2020, 4:48pm UTC](https://discourse.processing.org/t/question-about-loadstrings-function/20824/5 "2020-05-14T16:48:24Z")

</div>

Glad you worked it out!

Continues: [Question about GTextArea.setText() in G4P](https://discourse.processing.org/t/question-about-gtextarea-settext-in-g4p/20856)
