Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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,

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
)

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,

![]() |
![]() |
![]() |

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