Go Down

Topic: Clearing a String (Read 8 times) previous topic - next topic

iRagDoll

Hey Guys,

This is probably an easy question for most of you guys. What is the best way to clear a String value created by the String object?
All I am doing is filling up a String with values but then I need an easy way to clear it.

Thanks!

James C4S

Wouldn't:

Code: [Select]
String stringOne = "";

Do that?
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

iRagDoll

No I tried doing that. Here is the code that I am using.

Code: [Select]
while (Serial.available() > 0) {
      char c = Serial.read();
      readString += c;
  }
 
  if (readString == "<T1>")
  {
    Serial.println("Hello");
  }
  else
  {
    readString == "";
  }


All I need to do is in the else statement, clear the String readString so that I can read the next input properly.

kevinsa5

you have '=='. that's testing whether it's equal, try just a single '='

iRagDoll

Okay I tried that but now if I pass the String "<T1>" which should initialize the true case will not run. It wont print out anything.
Any ideas?

Really all I need to do is read a string from the Serial Port, and test if the String equals various String constants. Also, if the String from the Serial port does not equal any of the constant Strings, it should be completely cleared.

Thanks!

Go Up