![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 > 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 Specs![]() |
| | #3 (permalink) |
| | 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 - Can you explain exactly how this pattern works... what it searches for in the string? oRegEx.Pattern = " +" |
My System Specs![]() |
| | #4 (permalink) |
| | 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 - 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
| | #6 (permalink) |
| | 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 |
My System Specs![]() |
| | #7 (permalink) |
| | 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, " ")) 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 Specs![]() |
| | #8 (permalink) |
| | 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, " ")) 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 Specs![]() |
![]() |
| 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 | |||