# Serial.readStringUntil('\\n')

**URL:** <https://forum.arduino.cc/t/serial-readstringuntil-n/383772>\
**Category:** Programming\
**Created:** [May 3, 2016, 3:52pm UTC](https://forum.arduino.cc/t/serial-readstringuntil-n/383772 "2016-05-03T15:52:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![iSelector](https://avatars.discourse-cdn.com/v4/letter/i/f9ae1b/32.png) [@iSelector](https://forum.arduino.cc/u/iSelector)\
**Post date:** [May 3, 2016, 3:52pm UTC](https://forum.arduino.cc/t/serial-readstringuntil-n/383772/1 "2016-05-03T15:52:52Z")

</div>

I have some question about the function Serial.readStringUntil('\n');  
Why actually there is a need to wait for '\n' character when we want to get a string?  
Each string ends in '\n' character? as i know from c programming each string ends in '\0'...

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 3, 2016, 3:58pm UTC](https://forum.arduino.cc/t/serial-readstringuntil-n/383772/2 "2016-05-03T15:58:09Z")

</div>

> Why actually there is a need to wait for '\n' character when we want to get a string?

Because that is what you told the Arduino to do. Read a String Until a carriage return arrives.

> Each string ends in '\n' character?

That depends on what is sending the String. The Serial Monitor application has the option to append a carriage return and line feed to everything that it sends. If you use that option in that application, then, yes, every string ends in a carriage return.

---

<div class="post-metadata">

**Author:** ![econjack](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/econjack/32/1290082_2.png) [@econjack](https://forum.arduino.cc/u/econjack)\
**Post date:** [May 3, 2016, 4:03pm UTC](https://forum.arduino.cc/t/serial-readstringuntil-n/383772/3 "2016-05-03T16:03:55Z")

</div>

Try reading until you see a '\0' character. That might help explain Paul's answer. (Hint: There's a difference between terminating input and terminating a string.)

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [May 3, 2016, 4:23pm UTC](https://forum.arduino.cc/t/serial-readstringuntil-n/383772/4 "2016-05-03T16:23:45Z")

</div>

> Why actually there is a need to wait for '\n' character when we want to get a string?

Suppose that the string has 2 lines separated by a newline. This function would allow you to read and separate them.

Mind you, I think that I would rather read the input byte by byte and parse it myself because then I would know exactly what was going on.

---

<div class="post-metadata">

**Author:** ![iSelector](https://avatars.discourse-cdn.com/v4/letter/i/f9ae1b/32.png) [@iSelector](https://forum.arduino.cc/u/iSelector)\
**Post date:** [May 3, 2016, 5:45pm UTC](https://forum.arduino.cc/t/serial-readstringuntil-n/383772/5 "2016-05-03T17:45:00Z")

</div>

> PaulS:  
> Because that is what you told the Arduino to do. Read a String Until a carriage return arrives.  
> That depends on what is sending the String. The Serial Monitor application has the option to append a carriage return and line feed to everything that it sends. If you use that option in that application, then, yes, every string ends in a carriage return.

Ok thank you!! your answer very helped me!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 9:52pm UTC](https://forum.arduino.cc/t/serial-readstringuntil-n/383772/6 "2021-05-05T21:52:41Z")

</div>

Closed on May 5, 2021, 9:52pm UTC


