Getting Multiple Fragment Sections of Strings with Replace Function

Hi all,

I am trying to convert a Python output text file from a string to an integer.
The first thing I need to do is get rid of the parentheses surrounding the string.

This is the code I used:

String inData;
Servo servo1; //create servo

void setup()
{
  Serial.begin(115200); //originally 9600
  Serial.write('Setup complete');
  servo1.attach(9); //plug servo to pin 9
} 

void loop()
{
  
  while(Serial.available() > 0)
    {
      char received = Serial.read();
      //char received2 = Serial.read();
      inData += received;
      String servoAct = inData;  
      
      if (received == '\n')
        {
         servoAct.replace("(", "");
       servoAct.replace(")", "");
      //Serial.print(inData //, Dec);  
      //inData = ""; //clear buffer 
      
     
      Serial.print(servoAct);
      servoAct = ""; 
                                        //produces Python output
         }                            //second variable after comma
                                      //allows you to decide if DECimal,BINary, OCTal, or HEXadecimal              
     
      
    /*if( servoAct >= '66')
    {
    servo1.write(10);
    }
    else if(servoAct <= '55')
    {
    servo1.write(160);
    }
    */
    
}
}

When I run a Python test file through the code, this is the output I get:
1
13
1
13
134
1
13
134
Hello
1
13
134
Hello
If you’re reading this, everything is working
1
13
134
Hello
If you’re reading this, everything is working
Use BACKSLASH n at the end of a string backslash == \

Although it gets rid of the parentheses(the "backslash == " was originally in parentheses), it also sends multiple fragments of output. How can I fix this issue so that I get only one modified output?

I am trying to convert a Python output text file from a string to an integer.

No, you aren't. You're try to deal with a String. Not the same thing AT ALL.

You obviously have some idea what the length of the data stream will be, and there is an end of packet marker. Laziness is the only thing making you use a String instead of a string.

It would be helpful if you told us what the input stream was to produce the output you show. Also, as PaulS says, there is a world of difference between the String class of C++ and the simple string built from a char array. In this environment, you will be much better served forgetting about String and stick with char arrays.