Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Capture elements of a string into variables

Reply
 
Old 10-01-2008   #1 (permalink)
Highlander


 
 

Capture elements of a string into variables

Hello all.

The output of c:\windows\system32\iisapp.vbs is this:

w3wp.exe 7156 0
246,428 K

I'd like to take that output string and extract 4 variables from it.
Something like this:

var1= w3wp.exe
var2 = 7156
var3 = 0
var4 = 246,428

(The fifth variable - "K" - I'm not concerned with.)

Any help in how to extract the variables would be greatly appreciated.
Thanks.

- Dave




My System SpecsSystem Spec
Old 10-01-2008   #2 (permalink)
Pegasus \(MVP\)


 
 

Re: Capture elements of a string into variables


"Highlander" <tron9901@xxxxxx> wrote in message
news:595e352a-a18b-4b59-ad3a-e4f0d90da5e9@xxxxxx
Quote:

> Hello all.
>
> The output of c:\windows\system32\iisapp.vbs is this:
>
> w3wp.exe 7156 0
> 246,428 K
>
> I'd like to take that output string and extract 4 variables from it.
> Something like this:
>
> var1= w3wp.exe
> var2 = 7156
> var3 = 0
> var4 = 246,428
>
> (The fifth variable - "K" - I'm not concerned with.)
>
> Any help in how to extract the variables would be greatly appreciated.
> Thanks.
>
> - Dave
>
You could do something like this:

sOutput = "w3wp.exe 7156 0
246,428 K"
Set oRegEx = CreateObject("VBScript.RegExp")
oRegEx.Global = True
oRegEx.Pattern = " +"
aVariables = Split(oRegEx.Replace(sOutput, " "))

Your variables are now the elements of the array aVariables, e.g.
aVariables(0), aVariables(1) etc.


My System SpecsSystem Spec
Old 10-04-2008   #3 (permalink)
Highlander


 
 

Re: Capture elements of a string into variables

On Oct 1, 1:57*pm, "Pegasus \(MVP\)" <I....@xxxxxx> wrote:
Quote:

> "Highlander" <tron9...@xxxxxx> wrote in message
>
> news:595e352a-a18b-4b59-ad3a-e4f0d90da5e9@xxxxxx
>
>
>
>
>
Quote:

> > Hello all.
>
Quote:

> > The output of c:\windows\system32\iisapp.vbs is this:
>
Quote:

> > w3wp.exe * * * * * * * * * * *7156 * * * * * * * * * * * * * *0
> > 246,428 K
>
Quote:

> > I'd like to take that output string and extract 4 variables from it.
> > Something like this:
>
Quote:

> > var1= w3wp.exe
> > var2 = 7156
> > var3 = 0
> > var4 = 246,428
>
Quote:

> > (The fifth variable - "K" - I'm not concerned with.)
>
Quote:

> > Any help in how to extract the variables would be greatly appreciated.
> > Thanks.
>
Quote:

> > - Dave
>
> You could do something like this:
>
> sOutput = "w3wp.exe * * * * * * * * * * *7156 ** * * * * * * * * * * * *0
> 246,428 K"
> Set oRegEx = CreateObject("VBScript.RegExp")
> oRegEx.Global = True
> oRegEx.Pattern = " +"
> aVariables = Split(oRegEx.Replace(sOutput, " "))
>
> Your variables are now the elements of the array aVariables, e.g.
> aVariables(0), aVariables(1) etc.- Hide quoted text -
>
> - Show quoted text -
Thanks! That worked like a champ!

Can you explain exactly how this pattern works... what it searches for
in the string?

oRegEx.Pattern = " +"

My System SpecsSystem Spec
Old 10-04-2008   #4 (permalink)
Pegasus \(MVP\)


 
 

Re: Capture elements of a string into variables


"Highlander" <tron9901@xxxxxx> wrote in message
news:95436457-b7a5-4374-887a-77b5aeb85a6f@xxxxxx
On Oct 1, 1:57 pm, "Pegasus \(MVP\)" <I....@xxxxxx> wrote:
Quote:

> "Highlander" <tron9...@xxxxxx> wrote in message
>
> news:595e352a-a18b-4b59-ad3a-e4f0d90da5e9@xxxxxx
>
>
>
>
>
Quote:

> > Hello all.
>
Quote:

> > The output of c:\windows\system32\iisapp.vbs is this:
>
Quote:

> > w3wp.exe 7156 0
> > 246,428 K
>
Quote:

> > I'd like to take that output string and extract 4 variables from it.
> > Something like this:
>
Quote:

> > var1= w3wp.exe
> > var2 = 7156
> > var3 = 0
> > var4 = 246,428
>
Quote:

> > (The fifth variable - "K" - I'm not concerned with.)
>
Quote:

> > Any help in how to extract the variables would be greatly appreciated.
> > Thanks.
>
Quote:

> > - Dave
>
> You could do something like this:
>
> sOutput = "w3wp.exe 7156 0
> 246,428 K"
> Set oRegEx = CreateObject("VBScript.RegExp")
> oRegEx.Global = True
> oRegEx.Pattern = " +"
> aVariables = Split(oRegEx.Replace(sOutput, " "))
>
> Your variables are now the elements of the array aVariables, e.g.
> aVariables(0), aVariables(1) etc.- Hide quoted text -
>
> - Show quoted text -
Thanks! That worked like a champ!

Can you explain exactly how this pattern works... what it searches for
in the string?

oRegEx.Pattern = " +"

==================

My very limited knowledge of regular expressions tells me that it searches
for one or more spaces.


My System SpecsSystem Spec
Old 10-06-2008   #5 (permalink)
esska


 
 

Re: Capture elements of a string into variables

If you have problem with regular expressions in VBS check this
program: regexCreator_v1_0

For people who don't have time to count letters

Regards,
esska
My System SpecsSystem Spec
Old 10-06-2008   #6 (permalink)
Pegasus \(MVP\)


 
 

Re: Capture elements of a string into variables


"esska" <esska@xxxxxx> wrote in message
news:6f36be30-aa14-4e89-ab73-3d023ea8f4d5@xxxxxx
Quote:

> If you have problem with regular expressions in VBS check this
> program: regexCreator_v1_0
>
> For people who don't have time to count letters
>
> Regards,
> esska
Nice - Thank you for the tip!


My System SpecsSystem Spec
Old 10-07-2008   #7 (permalink)
Dr J R Stockton


 
 

Re: Capture elements of a string into variables

On Oct 1, 7:57*pm, "Pegasus \(MVP\)" <I....@xxxxxx> wrote:
Quote:

> oRegEx.Global = True
> oRegEx.Pattern = " +"
> aVariables = Split(oRegEx.Replace(sOutput, " "))
No doubt that works. A more general solution could be to use RegExp
Match, recognising the fields rather than the gaps between them.

--
(c) John Stockton, near London, UK. Posting with Google.
Mail: J.R.""""""""@physics.org or (better) via Home Page at
Web: <URL:http://www.merlyn.demon.co.uk/>
FAQish topics, acronyms, links, etc.; Date, Delphi, JavaScript, ....|
My System SpecsSystem Spec
Old 10-07-2008   #8 (permalink)
Monitor


 
 

Re: Capture elements of a string into variables


"Dr J R Stockton" <J.R.Stockton@xxxxxx> wrote in message
news:3c2b0e60-8fd0-4c10-8f69-038049e9a9ce@xxxxxx
On Oct 1, 7:57 pm, "Pegasus \(MVP\)" <I....@xxxxxx> wrote:
Quote:

> oRegEx.Global = True
> oRegEx.Pattern = " +"
> aVariables = Split(oRegEx.Replace(sOutput, " "))
No doubt that works. A more general solution could be to use RegExp
Match, recognising the fields rather than the gaps between them.

--
(c) John Stockton, near London, UK. Posting with Google.
Mail: J.R.""""""""@physics.org or (better) via Home Page at
Web: <URL:http://www.merlyn.demon.co.uk/>
FAQish topics, acronyms, links, etc.; Date, Delphi, JavaScript, ....|

================

Care to give a working example?


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Using @ Sign at String Variables? .NET General
question about auto-expanding variables in a string PowerShell
Re: best way to break string into variables PowerShell
Capture a string of characters and use as filename. PowerShell
SQL insert string with variables in foreach PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46