LIKE keyword in VB6

隐身守侯 提交于 2019-12-23 02:49:39

问题


I saw an example code as below

If numb Like "[0-9]" Then
End If

Here numb is a string holding one character.

What is the LIKE keyword in VB6? Is there any documentation available?


回答1:


Like Operator (Visual Basic for Applications Reference)

Used to compare two strings.

Syntax:

result = string Like pattern



回答2:


To have "Like" comparing the string "ABC", you must use * to mean "0 or any number of".

E.g: "ABC" Like "[A-Z]" results FALSE because "ABC" is not a 1-char long string, but "ABC" Like "*[A-Z]" returns TRUE because "ABC" has many chars in A-Z range

Cheers... Jorge




回答3:


Examples:

"G??" Like "God"

To find sentences that must have 3 characters start with capital G

"Prophet Muhammad (PBUH)" Like "Prophet*"

To find sentences with any length but start with Prophet

"*Islam*" Like "The only logical religion is Islam but they are adding rumors to it"

To find sentences with any length that contains Islam

"##days" Like "40days"

To find sentences that must have 6 characters and must start with 2 numbers and must end with days

"Only[01234][34]DaysDon'tDoSinThenYou'llSeeTheReality" Like "Only40DaysDon'tDoSinThenYou'llSeeTheReality"

Everything inside [ ] means: OR

0 OR 1 OR 2 OR 3 OR 4

3 OR 4

If you input one of them in the exact location. it returns true

In the following example, I must use the pattern otherwise I'll get error while typing:

Private Sub Text2_Change()

With Text2
    If .Text Like "*/*/####" Then
        .ToolTipText = DATE_TOOLTIP_ADDED(.Text)
    End If
End With

End Sub



来源:https://stackoverflow.com/questions/15475919/like-keyword-in-vb6

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!