Problem i face in serial communication

Hello,

You receive a string which includes a newline character ( β€˜\n’ )

You need to remove the newline character ( β€˜\n’ ) that is in the received string before splitting it so you can convert to an int.

Example:

https://processing.org/reference/trim_.html
https://processing.org/reference/String.html (discusses newline character and escape sequences such as \n)

:slight_smile:

String s1 = "123,456,890\n";
String [] list1 = split(s1, ',');

printArray(list1);
println(int(list1[2]));
println();

String s2 = "123,456,890\n";
s2 = trim(s2);

String [] list2 = split(s2, ',');

printArray(list2);
println(int(list2[2]));
println();

3 Likes