Partial matching search algorithm.

Started by hutch--, January 15, 2008, 03:03:31 AM

Previous topic - Next topic

hutch--

This example contains a partial matching algorithm which for searching for parts of strings. It should not be confused with a wildcard string matching algorithm similar to those used on command lines.

There re times when youy need to search for highly similar strings that only have minor variations. This algo is design to do this.

Just as an example with the search patter "m*st" it will find words like mast, mist, most and must. The algo allows the wildcard character "*" at the beginning, through the middle and at the end of the search pattern.

The algo uses direct addressing so it can be used with basic string, ASCIIZ string and direct memory allocated text.

[attachment deleted by admin]
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

hrxxx

Help..Please
I have used code above for PB 9.0
really work,
But i will use that in Library (DLL)
I change this
    Local txt   As Asciiz * 260
    Local patn  As Asciiz * 32
    ptxt  = VarPtr(txt)
    ppatn = VarPtr(patn)

With
    Local txt   As String
    Local patn  As String
    ptxt  = StrPtr(txt)
    ppatn = StrPtr(patn)

It's not work, i will call my PB DLL from VB 6.0,
VB doesnot support Asciiz  :(
How to resolved it?

::)

hutch--

Instead of trying to modify it, look at the prototype (declaration) and emulate this from VB.


FUNCTION partial(ByVal startat as DWORD,ByVal psrc as DWORD,ByVal ppatn as DWORD) as DWORD


These are the three arguments,

'         1.  startat :   zero based offset from start address
'         2.  psrc    :   address of zero terminated source to search
'         3.  ppatn   :   address of zero terminated pattern to search


That is the form you must emulate oin VB, a start location in the string and two addresses, first is the source, second is the pattern. You export the function in the DLL like normal, write your declaration in VB and call it using the correct data types.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jj2007

Quote from: hutch-- on January 15, 2008, 03:03:31 AMThe algo allows the wildcard character "*" at the beginning, through the middle and at the end of the search pattern.

Just out of curiosity: Could you give an example where *word or word* yield different results than word?

oex

Quote from: jj2007 on February 20, 2010, 12:45:42 PM
Just out of curiosity: Could you give an example where *word or word* yield different results than word?

I didnt check it but would suggest beginning/end of containing string ie word* should not match word<end> *word should not match <start>word. If * is only arguement you have no other way of saying starts with or ends with
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

hrxxx

Quote from: hutch-- on February 20, 2010, 12:08:00 PM
Instead of trying to modify it, look at the prototype (declaration) and emulate this from VB.


FUNCTION partial(ByVal startat as DWORD,ByVal psrc as DWORD,ByVal ppatn as DWORD) as DWORD


These are the three arguments,

'         1.  startat :   zero based offset from start address
'         2.  psrc    :   address of zero terminated source to search
'         3.  ppatn   :   address of zero terminated pattern to search


That is the form you must emulate oin VB, a start location in the string and two addresses, first is the source, second is the pattern. You export the function in the DLL like normal, write your declaration in VB and call it using the correct data types.

yes i have doit, in VB it will be

Declare FUNCTION partial Lib "MYDLL.DLL" (ByVal startat as Long,ByVal psrc as long,ByVal ppatn as long) as long

When i call...

Dim A as string
Dim B as string
Dim C as long

A = "I Love PB"
B = "P*"
C = partial (0,strptr(A),strptr(B))

result always 0,

may be i must check it again....

:( :(