Search code examples
visual-foxpro

How to check whether a character expression contains a "*" in the beginning of the text using the like function


cFilterprodname=upper(thisform.textbox1.text)

IF LIKE('*'+"%",cFilterprodname)=.T.
        MESSAGEBOX("* found in the beginning")
ELSE
        MESSAGEBOX("* not found in the beginning")
ENDIF 

This is the code which I tried and it is jumping to else block even if it has '*' in the beginning. Can someone help me?


Solution

  • That's not how the LIKE function works. First, the '*' is a wildcard, matching any number of characters, so it's not going to match on the character.

    Second, from the help file:

    cExpression2 must match cExpression1 letter for letter in order for LIKE( ) to return true (.T.).

    If you want to check if the first character is a '*', this would work and should be easier to understand.

    IF LEFT(cFilterprodname, 1) == "*"
            MESSAGEBOX("* found in the beginning")
    ELSE
            MESSAGEBOX("* not found in the beginning")
    ENDIF