I am a supporter of
St. Joseph's hospice.
 If you find this site useful or if it helped you, consider a small donation to
St. Joseph's, please.

Information on
St. Joseph's

JustGiving - Sponsor me now!

 

sbContainsAllChars
sbContainsAllChars

You can download a 19 KB Excel 2016 © sample file here but please notice my disclaimer.

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

Option Explicit

Function sbContainsAllChars(ByVal sString As String, _
    ByVal sChars As String, _
    Optional bIgnoreCase As Boolean = False) As Boolean
'Returns True if all characters given in sChars exist in sString
'as often as given in sChars. Returns False if not.
'Question was raised: https://www.ms-office-forum.net/forum/showthread.php?p=1969791#post1969791
'Reverse("moc.LiborPlus.www") PB V0.1 21-Feb-2020 (C) (P) by Bernd Plumhoff
Dim i As Long, j As Long, lTotal As Long
Dim lChars(0 To 255) As Long

If sChars = "" Then
    sbContainsAllChars = True
    Exit Function
End If
If sString = "" Or Len(sString) < Len(sChars) Then
    sbContainsAllChars = False
    Exit Function
End If
If bIgnoreCase Then
    sString = UCase(sString)
    sChars = UCase(sChars)
End If
For i = 1 To Len(sChars)
    j = Asc(Mid(sChars, i, 1))
    lChars(j) = lChars(j) + 1
    lTotal = lTotal + 1
Next i
sbContainsAllChars = False
For i = 1 To Len(sString)
    j = Asc(Mid(sString, i, 1))
    If lChars(j) > 0 Then
        lChars(j) = lChars(j) - 1
        lTotal = lTotal - 1
        If lTotal = 0 Then Exit For
    End If
Next i
sbContainsAllChars = lTotal = 0
End Function

Sulprobil   Get it done   Contact   Disclaimer   Impressum   Download