首页 > 解决方案 > 数字是否在字符串中的特定位置?

问题描述

我只想知道是否可以检查字符串中特定位置是否有数字

Sub test()

Dim a As String
a = "TestTestTest12"

'If (the 13th and the 14th positon are numbers) Then ...

End Sub

标签: vba

解决方案


使用以下:

Function IsNumberAtPosition(s As String, pos As Integer) As Boolean
  IsNumberAtPosition = IsNumeric(Mid(s, pos, 1))
End Function

用法:

IsNumberAtPosition("TestTestTest12", 13)

推荐阅读