Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem with removing something from string
Message
From
27/01/2001 20:44:35
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00469416
Message ID:
00469459
Views:
28
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<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.Expn1
    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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform