JSI Tip 9451. How can I return the numeric characters in an input string?

Jerold Schulman

June 13, 2005

1 Min Read
ITPro Today logo in a gray background | ITPro Today


I have scripted Numbers.bat to return the numeric characters in a given string.

The syntax for using Numbers.bat is:

call Numbers Input Output

Where Input contains the the input string and Output is a call directed environment variable that will contain the numeric character from Input. If no numeric characters exist in Input, Output will be NOT Defined.

Numbers.bat contains:

@echo offif {%2}=={} @echo Syntax: Numbers String StrNumbers&goto :EOFif exist "%TEMP%Numbers.vbs" goto doit@echo dim str>"%TEMP%Numbers.vbs"@echo Set objshell = CreateObject("WScript.Shell")>>"%TEMP%Numbers.vbs"@echo Set objArgs = WScript.Arguments>>"%TEMP%Numbers.vbs"@echo str=objArgs(0)>>"%TEMP%Numbers.vbs"@echo wscript.echo GetNumbersOnly(str)>>"%TEMP%Numbers.vbs"@echo. >>"%TEMP%Numbers.vbs"@echo function  GetNumbersOnly(str)>>"%TEMP%Numbers.vbs"@echo.     with new regexp>>"%TEMP%Numbers.vbs"@echo.        .pattern = "D">>"%TEMP%Numbers.vbs"@echo.        .global = true>>"%TEMP%Numbers.vbs"@echo.        GetNumbersOnly = .replace(str,"")>>"%TEMP%Numbers.vbs"@echo.    end with>>"%TEMP%Numbers.vbs"@echo end function>>"%TEMP%Numbers.vbs":doitset %2=for /f "Tokens=*" %%a in ('cscript.exe //nologo "%TEMP%Numbers.vbs" %1') do ( set %2=%%a)



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like