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


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 off
if \{%2\}==\{\} @echo Syntax: Numbers String StrNumbers&goto :EOF
if 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"
:doit
set %2=
for /f "Tokens=*" %%a in ('cscript.exe //nologo "%TEMP%\Numbers.vbs" %1') do (
 set %2=%%a
)



Please or Register to post comments.

IT/Dev Connections

Las Vegas
September 30th - October 4th

Paul ThurottYou'll have the opportunity to experience:
• The Microsoft
Technology Roadmap
• Office 365 Implementation
• Hyper-V Optimizing
• Windows 8 Deployment
and much more!

Come See Paul Thurrott & Rod Trent in Person!

Early Registration Now Open

Upcoming Training

Mastering SharePoint 2013: Succeeding, Not Just Surviving

Building on the success of the “Mastering SharePoint 2010” seminars, the presenters have updated the content to cover the latest and greatest SharePoint product: SharePoint 2013. While SharePoint 2013 is relatively new on the marketplace, the presenters have been working with SharePoint 2013 for well over a year, and have implemented it with a number of clients in production environments.

Register Now

Current Issue

May 2013 - The NameTranslate object is useful when you need to translate Active Directory object names between different formats, but it's awkward to use from PowerShell. Here's a PowerShell script that eliminates the awkwardness.

CURRENT ISSUE / ARCHIVE / SUBSCRIBE

Windows Forums

Get answers to questions, share tips, and engage with the Windows Community in our Forums.