Function indexOF slightly modified

HI;

I have a program like this:

String  inputString = "";         // a string to hold incoming data
boolean stringComplete = false;   // whether the string is complete

int     CmIdx0;                   // Input line indexes;
int     CmIdx1;
int     CmIdx2;
int     CmIdx3;

String  fstArg;                   // line arguments converted
String  secArg; 
String  trdArg; 
String  frtArg;
String  fthArg;

void setup() {
   Serial.begin(9600);            // initialize serial:
   inputString.reserve(200);      // reserve 200 bytes for the inputString:
   

}

void loop() {
   if (stringComplete) 
   {
      inputString.toUpperCase();
      Serial.println(inputString);    // print the string when a newline arrives:
      CmIdx0 = inputString.indexOf(',');
      CmIdx1 = inputString.indexOf(',' , CmIdx0 +1); 
      CmIdx2 = inputString.indexOf(',' , CmIdx1 +1); 
      CmIdx3 = inputString.indexOf(',' , CmIdx2 +1); 
      
      fstArg = inputString.substring(0,CmIdx0);
      secArg = inputString.substring(CmIdx0+1,CmIdx1);
      trdArg = inputString.substring(CmIdx1+1,CmIdx2); 
      frtArg = inputString.substring(CmIdx2+1,CmIdx3);
      fthArg = inputString.substring(CmIdx3+1);;


// these lines are for test only - will be deleted i the future.

      Serial.print(fstArg ); 
      Serial.print(" "); 
      Serial.print(secArg ); 
      Serial.print(" "); 
      Serial.print(trdArg ); 
      Serial.print(" "); 
      Serial.print(frtArg ); 
      Serial.print(" "); 
      Serial.print(fthArg ); 
      Serial.print(" "); 

      Serial.println(""); 
        
      inputString = "";               // clear the string:
      stringComplete = false;
   }
}

void serialEvent() 
{
  while (Serial.available()) 
  {
    char inChar = (char)Serial.read();      // get the new byte:
    inputString += inChar;                  // add it to the inputString:
    if (inChar == '\n')                     // if the incoming character is a newline, set a flag
                                            // so the main loop can do something about it:
    {
      stringComplete = true;
    }
  }
}

int MinIdxOf(String Buffer)
{
  for ( int i = 0; i < Buffer.length - 1; i++)
  {
    if ((Buffer[i] == " " ) || (Buffer[i] == "," ))
       return i;
  }
  return -1;
}

I read a line from the serial.event (eg: A,0000,0000,0000,0000) .

A letter ( can be A-Z uppercase) followed by 2 - 4 numbers (param1 - param4) . And the separators can be SPACE OR COMMA. (Comma shown here.)

Instead of using the STANDARD indexOF(char c) i want to use my own MinIdxOf(String Buffer), because both a Comma OR space will be accepted as separator at address I.

But the MinIdxOf(String Buffer) function is not working (invalid use of Member Function (did you forgot he '0' ?)

Now I have 2 questions:

1: What am I doing wrong in MinIdxOf(String Buffer) function, and how do I make I work ?

2: Later I want to include HEX-string (EG: B 01 FFFF FEDF 0099 (space(s) used here) and is there a smart way to convert param1 - param 4 (including HEX-strings) to an Integer ?

KRIS

What am I doing wrong in MinIdxOf(String Buffer) function, and how do I make I work ?

Well, the first thing to do is to post your code in code tags so that it is readable and does not display with part of it were in italics.

I assume that you have read the advice in read this before posting a programming question
and chose to ignore it.

#UKHelibob

You wrote:

Re: Function indexOF slightly modified
#1
Today at 01:37 pm
Quote

What am I doing wrong in MinIdxOf(String Buffer) function, and how do I make I work ?

Well, the first thing to do is to post your code in code tags so that it is readable and does not display with part of it were in italics.

I assume that you have read the advice in read this before posting a programming question
and chose to ignore it.

"

OK you got me (again!)

To be honest, I have not used the forum very much. And YES, I have read the "read this before posting a programming question" article you are referring to. Months ago. But I have forgotten most of the text.

But I have read It again. And I can guarantee that this mistake will never happen again.

KRIS

snestrup2000:
But I have read It again. And I can guarantee that this mistake will never happen again.

Just edit your opening post

Type
** **[code]** **
before the code
Type
** **[/code]** **
after the code

Problem solved

HI,

I found one of my errors.

In C++ you use FUNCTION.PARAMETER( ) . (parantheses AFTER parameter - I was not aware of that.

I am a Delphi user and not C++ .

Kris

snestrup2000:
In C++ you use FUNCTION.PARAMETER( ) . (parantheses AFTER parameter - I was not aware of that.

No.

In C++ you use Object.function(functionParameter).