Sign in to follow this  
Followers 0
jdickens

Recursive Strip Non-numerics from a String

3 posts in this topic

#1 ·  Posted (edited)

;^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v

Func StripNonNum($A_Val1) ;recursive fn
 ;WILL return multiple "." if present.  WILL return "." at front or tail of string if approp.
  If $A_Val1 <> "" Then
    $CharInQuest = StringLeft($A_Val1, 1)
    If StringIsDigit($CharInQuest) Or ($CharInQuest = ".") Then
      Return $CharInQuest & StripNonNum(StringTrimLeft($A_Val1, 1))
    Else
      Return StripNonNum(StringTrimLeft($A_Val1, 1))
    EndIf
  Else
    Return ""
  EndIf
EndFunc
;^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v

Edited by jdickens

If I am too verbose, just say so. You don't need to run on and on.

Share this post


Link to post
Share on other sites

thank you, very useful.


mouse not found....scroll any mouse to continue.

Share this post


Link to post
Share on other sites

thank you, very useful.

C'mon ... this topic is 3 and a half + years old. Did you really need to bring it back from the dead?

Besides, you can do it with one line of code:

$s_string = "t3902ks09a.d909.test"
$s_string = StringRegExpReplace($s_string, "([\d\.]+)|(\D)", "\1")
MsgBox(0, 0, $s_string)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0