How to compare strings?

  • I have a string variable STRIN[100] that is accepting string input from an external source...


    I want to process this via a few IF statements and react accordingly.


    How would I compare to see if STRIN[] == OTHER_STR[] ?

  • No its available since quite some time:
    BOOL StrComp (CHAR strComp1[470] :IN, CHAR strComp2[470] :IN, CASE_SENSE_T CaseSens :IN)


    strComp1 string to compare with strComp2
    strComp2 string to compare with strComp1
    CaseSens case sensitive or not (#CASE_SENS, #NOT_CASE_SENS)
    return value Returns TRUE if the strings are equal


    The following simple test worked fine for me


    bool result
    ...
    result = StrComp ("ABC”, "ABC”, (#CASE_SENS)) 
    result = StrComp ("ABC”, "abc”, (#NOT_CASE_SENS))
    result = StrComp ("ABC”, "abc”, (#CASE_SENS))
    result = StrComp ("ABC”, "acb”, (#NOT_CASE_SENS))


    Did you assign your result to a boolean?


    Fubini

  • Hallo ,Ich Habe eine KRC1 V4.1.7 SP5, und versuche gerade Strings zu vergleichen.

    Bin noch Anfänger habe die RS232 über com2 am laufen und möchte darüber strings vergleichen.

    Fehlermeldung Name nicht als Funktion vereinbart kommt wenn ich das schreibe

    IF StrComp (RX_Buffer[],RX_BUFFER_SOLL[],#CASE_SENS)==TRUE THEN

    Was mus ich denn genau declarieren um die Funktion ans laufen zu bekommen?

    Habe StrComp als BOOL schon versucht.

  • please use English in this forum.

    that KSS is too old and does not have string functions, ON_ERROR_PROCEED, $ERR etc.

    this means you need to use a workaround such as external function or using fixed length strings where you specify the max length to compare.


    example comparing first 3 characters (match):


    example comparing 5 characters (mismatch):


    not sure how to check string length in so old KSS so your strings may need to be padded with spaces

    1) read pinned topic: READ FIRST...

    2) if you have an issue with robot, post question in the correct forum section... do NOT contact me directly

    3) read 1 and 2

Advertising from our partners