Here's my attempt at your request (from your first post):
type Cmp_t
s as string ` The word
a as integer ` Count of this word in a$
b as integer ` COunt of this word in b$
endtype
dim Comparison() as Cmp_t
a$="my name is John"
b$="John is my name"
` Split a$ and add it to the Comparison array
split string a$, " "
for i = 1 to split count()
if split word$(i) <> "" then CheckString( split word$(i), 0 )
next
` Split b$ and add it to the comparison array in the same way
split string b$, " "
for i = 1 to split count()
if split word$(i) <> "" then CheckString( split word$(i), 1 )
next
` Just for neatness, sort the words alphabetically
sort array Comparison(), 1
` Now just print the results
for i = 0 to array count( Comparison() )
print padright$( Comparison(i).s, 20 );
print padleft$( str$(Comparison(i).a), 5 );
print padleft$( str$(Comparison(i).b), 5 );
print ""
next
wait key
end
function CheckString(s as string, a_or_b as integer)
local i as integer
s = lower$(s)
` Search for the string using a simple linear search
for i = 0 to array count(Comparison())
if s = Comparison(i).s
` Found it, so increment the appropriate counter and exit the function
inc Comparison(i).a, (a_or_b = 0) ` if a_or_b is set to zero then this will increment, and the next won't
inc Comparison(i).b, (a_or_b = 1) ` if a_or_b is set to one then this will increment, and the previous won't
exitfunction
endif
next i
` Not found, so add to the bottom
array insert at bottom Comparison()
Comparison().s = s
Comparison().a = (a_or_b = 0)
Comparison().b = (a_or_b = 1)
endfunction
All it does at the moment is to generate a list & count of the words that appear in each of a$ and b$ - you can use that to calculate the similarity in whatever way you choose. If you also want to use other symbols as word separators (eg comma or full-stop), then just add those to the SPLIT STRING commands in both places.