|
-
Sep 4th, 2001, 02:50 PM
#1
Thread Starter
Addicted Member
Something like this?
VB Code:
Sub SubStrings(strFirst As String, strSecond As String)
'counter(i) will contain the no. of times a substring
'length i of strSecond appears in strFirst
Dim tmparr() As String
Dim tmpStr As String
Dim Counter() As Long
Dim i As Long, j As Long
ReDim Counter(Len(strSecond) )
For i = 1 To Len(strSecond)
For j = 1 To Len(strSecond) - i + 1
tmpStr = Mid$(strSecond, j, i)
tmparr() = Split(strFirst, tmpStr, , vbBinaryCompare)
Counter(i) = UBound(tmparr()) + Counter(i)
Next j
Next i
End Sub
-
Sep 4th, 2001, 03:42 PM
#2
Ok, I'll take a shot.
I have a function DelimitedString_NumberofStrings that will
retrieve the number of pieces of strings that are delimited by a
constant string:
xxx = "Thefoxwalksonthefloor"
DS_NumberOfStrings(xxx,"the") will return 3
and there are 3 fields:"","foxwalkson",and "floor"
Assuming that you have this function
Str1 ="Thefoxwalksonthefloor"
Str2="Samanthafoxfloorsthewalker"
i = 1
hits = 0
while i < (len(STR2)-2)
checkit=mid$(STR2,i,3)
hits = hits+DS_NumberOfStrings(STR1,checkit)
i = i + 1
wend
should do the trick.
Would you like the function list?
Good Luck
-
Sep 4th, 2001, 04:14 PM
#3
Lively Member
-
Sep 4th, 2001, 04:16 PM
#4
Lively Member
Derfarm,
I'd really appreciate the func.list so i can compare a little.
i'm a novice at this and probably have messed up my declarations etc. Since i have to compare 2 x 28000 strings (long ones) im also looking for ways to speed the basterd up a little
thnx in advance
remvs
-
Sep 4th, 2001, 04:18 PM
#5
Lively Member
i dont have the code here now, but i can post it tommorow from work if anyone wants to see it
remvs
-
Sep 4th, 2001, 04:39 PM
#6
Thread Starter
Addicted Member
VB Code:
Sub SubStrings(strFirst As String, strSecond As String)
'percentcorrect(i) will contain the % of substring of
'length i of strSecond is succesfully matched with a substring of
'strFirst
Dim tmparr() As String
Dim tmpStr As String
Dim Counter As Long
Dim i As Long, j As Long
Dim percentcorrect() As Long
ReDim percentcorrect(Len(strSecond))
For i = 1 To Len(strSecond)
For j = 1 To Len(strSecond) - i + 1
tmpStr = Mid$(strSecond, j, i)
tmparr() = Split(strFirst, tmpStr, , vbBinaryCompare)
Counter = UBound(tmparr()) + Counter(i)
Next j
percentcorrect(i) = 100 * Counter /(Len(strSecond) - i)
Next i
End Sub
Also, assuming you only use letters in your string, a 3 chr string is 26 / no. of comparisons more likely to occur.
ie, if you have 2 * 4chr length strings,
prob. of finding 1 match for a 2chr substring is: 3 * 3 / 26^2
prob. of finding 1 match for a 3chr substring is: 2 * 2 / 26^3
General formula for the probability of 1 substring (length x), of String 1 (length y) occuring in String 2 (length z) is:
(y + 1 - x) * (z + 1 - x) / 26^x
-
Sep 4th, 2001, 05:24 PM
#7
Lively Member
Chrisf,
The formula at the bottom was what i needed! with that i can calculate the probability.
Thnx (all of u guys)
Remvs
-
Sep 4th, 2001, 05:40 PM
#8
Thread Starter
Addicted Member
You can expand it to find the prob. of n substrings ( length x )
of string 1 occuring in string 2. It will be a Geometric series,
First term n= (y + 1 - x) * (z + 1 - x) / 26^x
Ration = (y + 1 - x)
Giving: ((y + 1 - x) * (z + 1 - x) / 26^x )* (1 - (y + 1 - x)^ n) / (y - x)
if I've got the correct ratio.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|