Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Quickly alltrim non-alpha chars from string
Message
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9
Miscellaneous
Thread ID:
01037589
Message ID:
01038100
Views:
21
>Hi,
>
>>>
>Thanks again for the regex approach. I'm going to use that on another, unrelated task.
>>>
>This is a lot faster (but still doesn't beat Fox on short strings) :-)
>
>DEFINE CLASS Reg AS LINE
>  oRegExp1 = .NULL.
>  oRegExp2 = .NULL.
>  FUNCTION INIT()
>    WITH THIS
>      .oRegExp1 = CREATEOBJECT("VBScript.RegExp")
>      .oRegExp2 = CREATEOBJECT("VBScript.RegExp")
>      .oRegExp1.PATTERN = "^[^a-zA-Z]*"
>      .oRegExp2.PATTERN = "[^a-zA-Z]*$"
>    ENDWITH
>  ENDFUNC
>  FUNCTION NonAlphaTrim (cString)
>    WITH THIS
>      RETURN .oRegExp2.REPLACE(.oRegExp1.REPLACE(cString,""),"")
>    ENDWITH
>  ENDFUNC
>ENDDEFINE
>Good luck,
>Viv

Would having one regexp object be slightly faster?
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