Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Subject: Split a String - DOS, Batch script

Original Message
Name: dos4google
Date: May 1, 2008 at 10:46:39 Pacific
Subject: Split a String - DOS, Batch script
OS: XP
CPU/Ram: 3gb
Model/Manufacturer: Dell
Comment:
Hi all,

I have a string that I need to split and extract a particular part of the string:

Total Physical Memory: 3,326 MB

What I want is to split the string into components by spaces and then get the number at the end...

So this would give me the following components once split: Total, Physical, Memory:, 3,326, MB...

Any suggestions would be appreciated,


Report Offensive Message For Removal

Response Number 1
Name: klint
Date: May 1, 2008 at 13:53:06 Pacific
Subject: Split a String - DOS, Batch script
Reply: (edit)
Is this, by any chance, the output of the systeminfo command? Was Razor2.3's solution, using VBScript, not good enough for you? If you use the systeminfo command, that will give you the answer you want, but it does a lot more than just check memory and therefore takes a long time to run (by comparison, Razor's VBScript is almost instantaneous.) Anyway, here's the solution:

@echo off
set ans=Total Physical Memory: 3,326 MB
echo Parsing the string "%ans%":
for /f "tokens=1-5" %%a in ("%ans%") do (
echo Word 1: %%a
echo Word 2: %%b
echo Word 3: %%c
echo Word 4: %%d
echo Word 5: %%e
)


Report Offensive Follow Up For Removal

Response Number 2
Name: dos4google
Date: May 1, 2008 at 15:18:46 Pacific
Subject: Split a String - DOS, Batch script
Reply: (edit)
Thanks this is what I am after and would prefer to have it as a batch script. The only issue now is getting the "Total Physical Memory: 3,326 MB" by running : systeminfo | Find "Total Physical Memory" into a variable. So I thought I could do this:

set MEMORY=systeminfo | Find "Total Physical Memory" which would set the value "Total Physical Memory: 3,326 MB" into the %MEMORY% variable but this doesnt work. So esentially this script would run the systeminfo command, parse for the line I am after and then store this in a variable all from the same script. The issue is get the value of the systeminfo command into a variable from the same script...

Does anyone have any suggestions?

Thanks,


Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Split a String - DOS, Batch script

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software



Version Tracker Pro
Keep your software current and secure, effortlessly

Click Here for a Free Scan

Driver Agent
Automatically find the latest drivers for your computer.
Click Here for a Free Scan



The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC