none
Split and Replace Functions (ps1 to vbs) RRS feed

  • Question

  • Guru's,

    I am having a difficult time converting these PS functions into VBS.

    Any help would be greatly appreciated!

    $sName=$line.Split(" ")[0]
    
    $sValue=[int]$line.Split(" ")[1].Replace("%","").Trim()
    Thanks!

    Thursday, April 23, 2015 4:22 PM

Answers

  • VBScript does have a Split function that returns an array from a string, as in:


    Dim MyString, MyArray
    MyString = "This is a string"
    MyArray = Split(MyString, " ")
    For Each Element In MyArray
      WScript.Echo Element
    Next
    

    VBScript also has a Trim function for trimming spaces from the beginning and ending of the string.

    I would suggest starting by reading the VBScript documentation:

    http://msdn.microsoft.com/en-us/library/d1wf56tt.aspx

    As I mentioned in your other thread, this isn't a free code conversion service. It is customary to do the coding effort on your own, and get help with specific problems/questions, rather than asking others to write the code for you.


    -- Bill Stewart [Bill_Stewart]

    Thursday, April 23, 2015 4:33 PM
    Moderator

All replies

  • Scripting Guru's

    Need some help converting this PS script to a VBS. It is being used for OpsMgr.

    $StdOut -match '.*%st'
    $Value1 = [int32]($matches[0].Trim().Split(',')[3].Replace("%id","").Trim())
    
    $StdOut -match '.*$'
    $Value2 = [int32]($matches[0].Trim().Split(' ')[0])
    
    $StdOut -match '^.*'
    $Value3 = [int32]$matches[0]

    Thanks!


    Thursday, April 23, 2015 4:13 PM
  • Sorry, but this isn't a free code conversion service.

    What have you tried?


    -- Bill Stewart [Bill_Stewart]

    Thursday, April 23, 2015 4:28 PM
    Moderator
  • VBScript does have a Split function that returns an array from a string, as in:


    Dim MyString, MyArray
    MyString = "This is a string"
    MyArray = Split(MyString, " ")
    For Each Element In MyArray
      WScript.Echo Element
    Next
    

    VBScript also has a Trim function for trimming spaces from the beginning and ending of the string.

    I would suggest starting by reading the VBScript documentation:

    http://msdn.microsoft.com/en-us/library/d1wf56tt.aspx

    As I mentioned in your other thread, this isn't a free code conversion service. It is customary to do the coding effort on your own, and get help with specific problems/questions, rather than asking others to write the code for you.


    -- Bill Stewart [Bill_Stewart]

    Thursday, April 23, 2015 4:33 PM
    Moderator
  • Dim pat1 = ".*%st"
    Dim match1 as Match1 = Regex.Match1(stdOut, pat1)
    Dim val1 = match1.Trim()
    val1 = match1.Split(",")
    val1 = match1.Replace("%id","")

    Thursday, April 23, 2015 5:33 PM
  • It's not going to be possible to simply guess how to write the code.

    You're going to actually have to read the documentation:

    http://msdn.microsoft.com/en-us/library/d1wf56tt.aspx


    -- Bill Stewart [Bill_Stewart]

    Thursday, April 23, 2015 5:39 PM
    Moderator