Sulprobil
Search…
sbContainsAllChars
Name
sbContainsAllChars - True if all characters given in sChars exist in sString as often as given in sChars, False if not.
Synopsis
sbContainsAllCHars(sString, sChars, [bIgnoreCase])
Description
sbContainsAllChars retuns True if all characters given in sChars exist in sString as often as given in sChars, False if not.
Example
See graphic above
Options
sString String in which all characters will be searched.
sChars Characters which need to appear in sString. Note that characters can be stated more than once, then they need to appear as often in sString as in sChars.
bIgnoreCase Optional - standard value is False if not provided True - takes the summands as they are False - works on the summands' percentages to make all percentages add up to 100% exactly
bDontAmend Optional - standard value is False if not provided True - Function treats alls String as upper case False - Function is case sensitive
Please read my Disclaimer.
1
Function sbContainsAllChars(ByVal sString As String, _
2
ByVal sChars As String, _
3
Optional bIgnoreCase As Boolean = False) As Boolean
4
'Returns True if all characters given in sChars exist in sString
5
'as often as given in sChars. Returns False if not.
6
'Question was raised: https://www.ms-office-forum.net/forum/showthread.php?p=1969791#post1969791
7
'Reverse("moc.LiborPlus.www") PB V0.1 21-Feb-2020 (C) (P) by Bernd Plumhoff
8
Dim i As Long, j As Long, lTotal As Long
9
Dim lChars(0 To 255) As Long
10
11
If sChars = "" Then
12
sbContainsAllChars = True
13
Exit Function
14
End If
15
If sString = "" Or Len(sString) < Len(sChars) Then
16
sbContainsAllChars = False
17
Exit Function
18
End If
19
If bIgnoreCase Then
20
sString = UCase(sString)
21
sChars = UCase(sChars)
22
End If
23
For i = 1 To Len(sChars)
24
j = Asc(Mid(sChars, i, 1))
25
lChars(j) = lChars(j) + 1
26
lTotal = lTotal + 1
27
Next i
28
sbContainsAllChars = False
29
For i = 1 To Len(sString)
30
j = Asc(Mid(sString, i, 1))
31
If lChars(j) > 0 Then
32
lChars(j) = lChars(j) - 1
33
lTotal = lTotal - 1
34
If lTotal = 0 Then Exit For
35
End If
36
Next i
37
sbContainsAllChars = lTotal = 0
38
End Function
Copied!
sbContainsAllChars.xlsm
19KB
Binary
sbContainsAllChars.xlsm
Last modified 1yr ago
Copy link