Vbscript for calculating % of characters matching the input string
Hello,
I hope every one doing great.My issuse i need a vbscript/any corresponding logic/formulae for calculating the % of characters matching the input.
For example in my excel sheet if i have a word MICROSOFT and if iam search as MICRo it should give me the % of characters matching through vbscript r any other like macros r vlookup
Thanks
I hope every one doing great.My issuse i need a vbscript/any corresponding logic/formulae for calculating the % of characters matching the input.
For example in my excel sheet if i have a word MICROSOFT and if iam search as MICRo it should give me the % of characters matching through vbscript r any other like macros r vlookup
Thanks
0 Comments
[ + ] Show comments
Answers (2)
Please log in to answer
Posted by:
anonymous_9363
14 years ago
Any use to you? It's not of my own making but I'm sure I've used it in the past
'// =========================================================================================================
'// Name: GetSubstringCount
'// Purpose: Determines how many times one string occurs in another string
'// Input: strToLookFor - the string to look for
'// strSearch - the string to look in
'// blnIgnoreCase - If True, ignore case of both strings
'// Output: intStringCount - a 'ByRef' variable which will contain the number of occurrences
'// Returns: True/False
'// =========================================================================================================
Function GetSubstringCount(ByVal strToLookFor, ByVal strSearch, ByVal blnIgnoreCase, ByRef intStringCount)
'// Since VBS doesn't provide a string counter (i.e. how many times a string occurs in another string)
'// we hack it using Split: the UBound of the array will tell us how many occurrences there are, if any
'// assume the worst
GetSubstringCount = False
If Len(strToLookFor) = 0 Then
strMsg = "A parameter, 'strToLookFor', passed to " & strScriptName & ".GetSubstringCount is empty."
'errStatus = MsgUsr(strMsg, intButtonType, strScriptName & ".GetSubstringCount", intButtonPressed)
Exit Function
End If
If Len(strSearch) = 0 Then
strMsg = "A parameter, 'strSearch', passed to " & strScriptName & ".GetSubstringCount is empty."
'errStatus = MsgUsr(strMsg, intButtonType, strScriptName & ".GetSubstringCount", intButtonPressed)
Exit Function
End If
If blnIgnoreCase Then
intStringCount = UBound(Split(strSearch, strToLookFor))
Else
intStringCount = UBound(Split(UCase(strSearch), UCase(strToLookFor)))
End If
GetSubstringCount = True
End Function
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.