Remove a Line Break

I am writing a program, to get serial input string and then add three COMMAs with it. but I am facing a problem of a line gap (carriage return+linefeed) b/w string and COMMAs. Can you plz guide me on how do I resolve this problem and remove the line gap. below in my code.

import processing.serial.*;
Serial serialPort;
String input;

void setup() {
  serialPort = new Serial(this,"COM4",9600);
  serialPort.bufferUntil('\n'); }

void draw() {
  background(1);
}

void serialEvent(Serial serialPort) {
  input = serialPort.readString();
  for (int i=0 ; i<3; i++) {
  input = input + ",";
  }
println(input);
}

Answers

  • edited April 2015 Answer ✓

    ... but I am facing a problem of a line gap (carriage return+linefeed)...

    Dunno if I'm understanding it right, but mebe 2 trim() calls would remove the CR + LF endings? :-??
    Worth a try, right? 8-X

    void serialEvent(Serial serial) {
      input = serial.readString().trim().trim() + ",,,";
      println(input);
    }
    
Sign In or Register to comment.