The MASM Forum Archive 2004 to 2012

Project Support Forums => PowerBASIC Low Level Code => Topic started by: hutch-- on January 15, 2008, 03:03:31 AM

Title: Partial matching search algorithm.
Post by: hutch-- on January 15, 2008, 03:03:31 AM
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]
Title: Re: Partial matching search algorithm.
Post by: hrxxx on February 20, 2010, 12:50:45 AM
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?

::)
Title: Re: Partial matching search algorithm.
Post by: 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.
Title: Re: Partial matching search algorithm.
Post by: jj2007 on February 20, 2010, 12:45:42 PM
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?
Title: Re: Partial matching search algorithm.
Post by: oex on February 20, 2010, 01:51:25 PM
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
Title: Re: Partial matching search algorithm.
Post by: hrxxx on February 21, 2010, 12:44:38 AM
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....

:( :(