Computing.Net > Forums > Programming > Split a String - DOS, Batch script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Split a String - DOS, Batch script

Reply to Message Icon

Name: dos4google
Date: May 1, 2008 at 10:46:39 Pacific
OS: XP
CPU/Ram: 3gb
Product: 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,



Sponsored Link
Ads by Google

Response Number 1
Name: klint
Date: May 1, 2008 at 13:53:06 Pacific
Reply:

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
)


0

Response Number 2
Name: dos4google
Date: May 1, 2008 at 15:18:46 Pacific
Reply:

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,


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Split a String - DOS, Batch script

MS Dos batch Script Help www.computing.net/answers/programming/ms-dos-batch-script-help/14592.html

batch scripting www.computing.net/answers/programming/batch-scripting/15938.html

split a string in DOS www.computing.net/answers/programming/split-a-string-in-dos/19355.html