简体   繁体   中英

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?

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 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM