How to eliminate nextline in Serial data?

I’m trying to play wav file in arduino using serial. the code will read the serial and get the string and add the file extension. the problem is every time I read the serial it always get the string and has a next line that’s why the file extension goes next line.

here’s what a get:

A
.wav

what I need is:

A.wav without next line

Here’s my code:
#include “SPI.h”
#include <string.h>

TMRpcm tmrpcm;
String readString;

void setup(){
tmrpcm.speakerPin = 9;
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)) {
Serial.println(“SD fail”);
tmrpcm.setVolume(5);
return;
}
}

void loop(){
char incomingByte;
while (Serial.available()>0) {
delay(10); // if the data came

incomingByte = Serial.read(); // read byte

readString +=incomingByte;

}
if(readString != “”)
{
String extension =".wav";
String combine = readString + extension;
const char *url_complete = combine.c_str();

Serial.print(url_complete);
tmrpcm.play(url_complete);

}
readString = “”;

}

the problem is every time I read the serial it always get the string and has a next line

What have you got the line ending set to in the Serial monitor ?

I got this from the serial monitor.

A
.wav

I need is

A.wav

curlyBrace11:
I got this from the serial monitor.

That is not an answer to the question in Reply #1.

Read the question again.

...R

My code is working already. Thanks :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile:

curlyBrace11:
My code is working already. Thanks :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile:

For the benefit of other readers who may have a similar problem please explain how you solved the problem.

...R