Jump to content

[SOLVED] Sting == String compare does not work


photo

Recommended Posts

Hi

 

if(timeAtStartGobal == eventID_value) { 

 

}

 

Check if strings are the same does not work, why?

 

Comes from XML:

eventID_value = item.getArg("value");

 

 

Comes from date:

timeAtStartGobal = date("%2h:%02m");

Link to comment

Hi 

 

tried this but allways -1

 

int result = strncmp(upper(timeAtStartGobal),upper(eventID_value),5);
log.message("preamble state %d %s %s %d\n", state, timeAtStartGobal, eventID_value, result);
Link to comment

Hi 

 

This  is the code

 

eventID_value = item.getArg("value");

timeAtStartGobal = date("%2h:%02m");
 
if(state == 1) {
int result = strncmp(upper(timeAtStartGobal),upper(eventID_value),5);
log.message("preamble state %d %s %s %d\n", state, timeAtStartGobal, eventID_value, result);
}
Link to comment

Plus tried 

 

int result = strcmp(timeAtStartGobal, eventID_value);
log.message("preamble state %d %s %s %d\n", state, timeAtStartGobal, eventID_value, result);
 
still -1
Link to comment

Getting different lengths

 

timeAtStartGobal = date("%2h:%02m");
 
if(state == 1) {
int len = strlen (timeAtStartGobal);
int len2 = strlen (eventID_value);
 
int result = strcmp(timeAtStartGobal, eventID_value);
log.message("preamble state %d %s %s %d %d %d\n", state, timeAtStartGobal, eventID_value, result, len, len2);
}
Link to comment

OK 

 

By using trim on both strings eventID_value  and  timeAtStartGobal = trim(date("%2h:%02m"));

 

eventID_value = trim(eventID_valueHold);

 

we have a match 

 

Is this the right way to do it?

Link to comment

log.message("preamble state %d %s %s %d %d %d\n", state, timeAtStartGobal, eventID_value, result, len, len2);

 

state = 1;

 

timeAtStartGobal = 9:11

 

eventID_value = 9:11

 

result = 0; of strcmp

 

len = 4; //length of timeAtStartGobal

 

len2 = 4; // length of  eventID_value

Link to comment
×
×
  • Create New...