Gambas Documentation - /lang/comp

/lang/comp

# Comp

Result = Comp ( String1 AS String , String2 AS String [ , Mode AS Integer ] ) AS Integer

Compares two strings, and returns:

- `0` if the two strings are equal.

- `1` if String1 is strictly greater than String2.

- `-1` if String1 is strictly lower than String2.

The Mode parameter can be any combination defined in the Comparison methods page.

### Examples

    IF Comp(command, "open") = 0 THEN open_file

    DIM UserName AS String

    PRINT "Please Enter Your User Name:";
    INPUT UserName

    IF Comp(UserName, "Akiti") = 0 THEN
    PRINT "You Can Enter"
    ELSE
    PRINT "Sorry, You Cannot Enter"
    ENDIF

    ' This is illustrative example only.
    ' To actually delete the file you will need to write the proper code.

    DIM answer AS String

    PRINT "Do you want to delete the file? [y/n]"
    INPUT answer

    IF Comp(answer, "y", gb.text) = 0 THEN

      '...... (code to delete the file)
      '......
      '......

      ' If succesfull we print the following message
      PRINT "File Deleted"

    ELSE
      PRINT "File Not Deleted"
    ENDIF

### See also

- String.Comp

- String Functions

- Comparison methods