[Solved] How can I check if a space is in a String

Dear All,
I am getting the answer of a AT command

if(Serial1.available() > 0)
{
        if(x < BUFFERSIZE-1) // Do not fill the buffer more the it size
        {
           buffer[x] = Serial1.read();
           if(buffer[x] != 0x040)
           {  
             Serial.prinln(F("OK"));
           }
           else
           {
             Serial.println(F("Replace"));
           }
        }
}

If there a space, I need to replace it with a -
It always display OK

I tryed several things

if(buffer[x] != 0x040)
if(buffer[x] != '0x040')
if(buffer[x] != 0x20)
if(buffer[x] != '0x20')
if(buffer[x] != 32)
if(buffer[x] != "") // Dont compile
if(buffer[x] != '') // Dont compile
if(buffer[x] != " ") // Dont compile
if(buffer[x] != ' ') // Dont compile

How can I simply make false when there is a space
for exemple:
+CENG: 1 (Space bedore 1)

=( :.

How can I simply make false when there is a space for exemple:

Post all of your code correctly. For all we know, buffer is an array of floats, which explains why the code does not compile.

Oups sorry, It's done

Sorry for code display, I corrected it.

When I compare

if(buffer[x] == '\n')

or

if(buffer[x] == '\r')

It compile. So how can I do the same with a space?

So how can I do the same with a space?

if(buffer[x] == ' ')

If that doesn't compile, do not bother posting another snippet. Post ALL of your code and the EXACT error message.

If there a space, I need to replace it with a -

If you capture your String, you probably use a String function similar to below.

          if(readString.contains(" ")) { //test for character in string
            readString.replace(' ', '#');

http://arduino.cc/en/Tutorial/StringReplace

Hello,

if Serial.read()
return

+CENG: 1.1

and then

buffer[x]=Serial.read();
Serial.println(buffer[x]);

will display:

C
E
N
G
:
[Space]
1
.
1

Then (I wrote [Space] because I do not what to write

 if(buffer[x] != [Space])

Should display

OK for +
OK for C
OK for E
OK for N
OK for G
OK for :
Replace for the space
OK for 1
OK for .
OK for 1

My problem, it always display OK excepted when it does not compile because of ‘’ or “”

if(Serial1.available() > 0)
{
        if(x < BUFFERSIZE-1) // Do not fill the buffer more the it size
        {
           buffer[x] = Serial1.read();
           if(buffer[x] != [Space])
           {  
             Serial.prinln(F("OK"));
           }
           else
           {
             Serial.println(F("Replace"));
           }
        }
}

My worrie is which is the correct syntax to compare a Space.

To compare \n, I can write

 if(buffer[x] != '\n')

To be sincerely with you, there were another small bug, which did not help me and I finally found my needed answer

Here is the solution

char comp[2] = {' ','\0'};
if(buffer[x] != comp[0])
{
       Serial.println(buffer[x])
       start_record = true;
}
else
{
       Serial.println(F("Space"))
}

And I later tried and it works (finally)

if(buffer[x] != 0x20)

So this was the answer I needed

Cheers

if

Serial.read()

return

+CENG: 1.1

It doesn't. Serial.read() reads ONE byte.

           if(buffer[x] != [Space])

This is nonsense.

Here is the solution

More nonsense, because all you have posted is snippets.

Take your snippets to http://snippets-r-us.com, and do not come back here until you can post ALL of your code.

Dear Pauls,

My code is on my first post and re pasted in my last reply

It doesn't. Serial.read() reads ONE byte.

This I know, and it's what I explain in my last reply

buffer[x]=Serial.read();
Serial.println(buffer[x]);

will display:

+ C E N G : [Space] 1 . 1

if(buffer[x] != [Space]) //I wrote [Space] because I do not what to write, and this my question
           {  
             Serial.prinln(F("OK"));
           }
           else
           {
             Serial.println(F("Replace"));
           }

Should display

OK for + OK for C OK for E OK for N OK for G OK for : Replace for the space OK for 1 OK for . OK for 1

But as I stated, my problem is solved and it's works

If it does not make nosens, could you show an exemple or a better solution? To simply answer to that question

if(buffer[x] != 0x20) // where buffer[x] is egal to a space
           {  
             Serial.prinln(F("OK"));
           }
           else
           {
             Serial.println(F("Replace"));
           }