我正在处理一个宏,它接受当前值ActiveCell并根据选择的情况更改该值.
但是,我无法确定是否ActiveCell包含通配符字符串.我不确定我的语法是否正确.如何让我的选择案例进行比较?
Select Case ActiveCell.Value
Case ActiveCell.Value Like "*string*"
ActiveCell.Value = "contains string"
End Select
Run Code Online (Sandbox Code Playgroud) 我在使用“like”运算符时遇到问题。
我想在表中查找字符串,例如“地址#123”或“地址#56778”或“地址#2b”。所以,我在代码中这样写:
If m_Table.Rows(i).Item("NOTE").ToString Like "*ADDRESS #*" Then
Run Code Online (Sandbox Code Playgroud)
但是,代码将“#”读取为通配符,而不是简单字符。
如何重写我的代码以使其将 # 读取为简单字符,而不是通配符?
我需要编写一个函数来检测字符串输入是否是日期的有效格式.允许的格式是:
#### (e.g. 2003)
##/#### (e.g. 12/2003)
#/#### (e.g. 9/2003)
##/####-##/#### (e.g. 12/2003-04/2005)
Run Code Online (Sandbox Code Playgroud)
但我需要防止无效字符串(例如"20031","ABCD","200A").
我已经在VB中编写了一个函数来执行此操作(下面),但我需要在Javascript中执行此操作.
VB
Public Sub detectDateFormat(ByVal myDate As String)
If myDate Like "####" Then
'Do Stuff 1
ElseIf myDate Like "##/####" Or myDate Like "#/####" Then
'Do Stuff 2
ElseIf myDate Like "##/####-##/####" Then
'Do Stuff 3
Else
'Invalid date format
Exit sub
End If
End Function
Run Code Online (Sandbox Code Playgroud)
似乎javascript没有等同于"Like",并且检测一个字符是数字还是字母是很棘手的.任何人都可以建议一个好方法吗?
为什么Like功能不起作用?在这种情况下,它返回:
"不,这不对"
Sub test()
If "*?????? ?? ???????? ??-004#1500333*" Like "??????? ?? ???????? ??-004#1500333 ???.xlsx" Then
MsgBox "Yes, it is!"
Else
MsgBox "No, it's not"
End If
End Sub
Run Code Online (Sandbox Code Playgroud) excel ×2
vb.net ×2
vba ×2
wildcard ×2
cyrillic ×1
hash ×1
javascript ×1
select-case ×1
string ×1