您的位置:程序门 -> vb ->



字符匹配函数的修改问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


字符匹配函数的修改问题[无满意答案结贴,结贴人:huaxinrui]
发表于:2007-10-26 23:09:44 楼主
这是一位好心人在网上写的一段匹配函数,但是执行这段函数后两个字段中的数据有一个相同就匹配在了一起,我想改成改的匹配度低一点,比如说有五个字相同匹配在一起,哪位好心大哥帮我改改,另外再帮我写一段代码,使这个函数能在vb中使用,不胜感激!!!

执行语句:select   *   from   comparebase   inner   join   zd_yp5   on   alikepercentex(comparebase.xm_name,zd_yp5.yp_name);


public   function   alikepercentex(byval   strtextsrc   as   string,   _
                                                                                                                        byval   strtextdest   as   string,   _
                                                                                                                        optional   byval   blncasesensitive   as   boolean   =   false,   _
                                                                                                                        optional   byval   blnexactpositionmatch   as   boolean   =   false)   as   double
                       
                    dim   o_strtextsrc           as   string
                    dim   o_strtextdest           as   string
                       
                    dim   o_strtextlonger           as   string
                    dim   o_strtextshorter           as   string
                       
                    dim   o_strbytesrc           as   string
                    dim   o_strbytedest           as   string
                    dim   o_lnglength           as   long
                    dim   o_lngitems           as   long
                    dim   o_lngmatches           as   long
                    dim   o_lngstart           as   long
                       
                    if   not   blncasesensitive   then
                                    o_strtextsrc   =   ucase(strtextsrc)
                                    o_strtextdest   =   ucase(strtextdest)
                    else
                    end   if
                       
                       
                    if   o_strtextsrc   =   o_strtextdest   then                       '如果一致
                                       
                                    alikepercentex   =   100#
                       
                    else
                       
                                    if   len(o_strtextsrc)   =   len(o_strtextdest)   then
                                                    o_strtextlonger   =   o_strtextsrc
                                                    o_strtextshorter   =   o_strtextdest
                                    elseif   len(o_strtextsrc)   >   len(o_strtextdest)   then
                                                    o_strtextlonger   =   o_strtextsrc
                                                    o_strtextshorter   =   o_strtextdest
                                    else
                                                    o_strtextlonger   =   o_strtextdest
                                                    o_strtextshorter   =   o_strtextsrc
                                    end   if
                                                                       
                                    o_lnglength   =   len(o_strtextshorter)
                                                                       
                                       
                                    o_lngstart   =   instr(o_strtextlonger,   left(o_strtextshorter,   1))
                                       
                                    if   o_lngstart   then
                                       
                                                    o_lngmatches   =   1
                                       
                                                    for   o_lngitems   =   o_lngstart   +   1   to   len(o_strtextlonger)
                                                                       
                                                                    if   blnexactpositionmatch   then               '位置必须一致
                                                                                    o_strbytesrc   =   mid(o_strtextlonger,   o_lngitems,   1)
                                                                                    o_strbytedest   =   mid(o_strtextshorter,   o_lngitems   -   o_lngstart   +   1,   1)
                                                                                       
                                                                                    if   o_strbytesrc   =   o_strbytedest   then
                                                                                                    o_lngmatches   =   o_lngmatches   +   1
                                                                                    else
                                                                                    end   if
                                                                       
                                                                    else       '任意位置模糊匹配
                                                                                       
                                                                                       
                                                                    end   if
                                                    next
                                                       
                                                    alikepercentex   =   (o_lngmatches   /   o_lnglength)   *   100   \   1
                                                       
                                    else
                                                       
                                                    alikepercentex   =   0#
                                    end   if
                                       
                    end   if
     
    end   function


快速检索

最新资讯
热门点击