Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem with removing something from string
Message
 
 
To
27/01/2001 20:44:35
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00469416
Message ID:
00469463
Views:
33
Well, this is a test. Did I do something wrong? It works faster, but doesn't do anything:
local lcString
lcString=[SiteMstr.ccode="01" and inlist(TranMstr.Lender,"jfhjhfjf","fjsdkjfksfj") and PropMstr.LstSlDate>date() and tranmstr.date=date()]
lnSec=seconds()
oRegExp = CREATEOBJ('VBScript.RegExp')
oRegExp.Global = .t.                 && translate all occurances
oRegExp.IgnoreCase = .t.             && case insensitive
oRegExp.Pattern = '\b\w{4}MSTR\.(.)' && word boundary, followed by 4 word chars
                                     && followed by MSTR., followed by any char
                                     && other than a newline, remembered as $1
cTranslate = oRegExp.Replace(lcString,'$1')
? cTranslate
?seconds()-lnSec
lnSec=seconds()
?STRTRANC(lcString,"sitemstr.","")
?STRTRANC(lcString,"tranmstr.","")
?STRTRANC(lcString,"propmstr.","")
?seconds()-lnSec

*******************************************
FUNCTION STRTRANC
*-- non case-sensitive string translation
*******************************************
PARAMETERS Expc1, Expc2, Expc3, Expn1, Expn2
LOCAL Expr, lnat_pos, lnat_pos2, lnI, lnJ

IF EMPTY(m.Expc1).OR.EMPTY(m.Expc2)
  RETURN m.Expc1
ENDIF
m.Expr=m.Expc1
IF TYPE('m.Expn1')#'N'
  m.Expn1=1
ENDIF
IF TYPE('m.Expn2')#'N'
  m.Expn2=LEN(m.Expc1)
ENDIF
IF m.Expn1<1.OR.m.Expn2<1
  RETURN m.Expc1
ENDIF
m.lnI=0
m.lnJ=0
m.lnat_pos2=1
DO WHILE .T.
  m.lnat_pos=ATC(m.Expc2,SUBSTR(m.Expr,m.lnat_pos2))
  IF m.lnat_pos=0
    EXIT
  ENDIF
  m.lnI=m.lnI+1
  IF m.lnI=m.Expn2
    EXIT
  ENDIF
  m.lnat_pos2=m.lnat_pos+m.lnat_pos2+LEN(m.Expc3)-1
  IF m.lnat_pos2>LEN(m.Expr)
    EXIT
  ENDIF
ENDDO
RETURN m.Expr
>This beats RegExp for speed by a wide margin. Original Author is Ken Levy. This code was in his original GENSCRNX. The only difference with STRTRAN() is the third parameter is required in this version.
>
>
>*******************************************
>FUNCTION STRTRANC
>*-- non case-sensitive string translation
>*******************************************
>PARAMETERS Expc1, Expc2, Expc3, Expn1, Expn2
>LOCAL Expr, lnat_pos, lnat_pos2, lnI, lnJ
>
>IF EMPTY(m.Expc1).OR.EMPTY(m.Expc2)
>  RETURN m.Expc1
>ENDIF
>m.Expr=m.Expc1
>IF TYPE('m.Expn1')#'N'
>  m.Expn1=1
>ENDIF
>IF TYPE('m.Expn2')#'N'
>  m.Expn2=LEN(m.Expc1)
>ENDIF
>IF m.Expn1  RETURN m.Expc1
>ENDIF
>m.lnI=0
>m.lnJ=0
>m.lnat_pos2=1
>DO WHILE .T.
>  m.lnat_pos=ATC(m.Expc2,SUBSTR(m.Expr,m.lnat_pos2))
>  IF m.lnat_pos=0
>    EXIT
>  ENDIF
>  m.lnI=m.lnI+1
>  IF m.lnI    m.lnat_pos2=m.lnat_pos+m.lnat_pos2+LEN(m.Expc2)-1
>    LOOP
>  ENDIF
>  m.Expr=LEFT(m.Expr,m.lnat_pos+m.lnat_pos2-2)+m.Expc3+;
>    SUBSTR(m.Expr,m.lnat_pos+m.lnat_pos2+LEN(m.Expc2)-1)
>  m.lnJ=m.lnJ+1
>  IF m.lnJ>=m.Expn2
>    EXIT
>  ENDIF
>  m.lnat_pos2=m.lnat_pos+m.lnat_pos2+LEN(m.Expc3)-1
>  IF m.lnat_pos2>LEN(m.Expr)
>    EXIT
>  ENDIF
>ENDDO
>RETURN m.Expr
>
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform