Facility Control

 View Only
  • 1.  string parser with ogscript

    Posted 07-13-2015 15:21
    Hi,

    Is there a way to parse a string variable with ogscript?

    Let's say that I have a variable looking like this :mystring = "return value1, return value2, return value3"

    I would like to extract each invidual data between commas in order to apply the correct action on it.

    Is it something feasible?

    Thanks

    Bruno


  • 2.  RE: string parser with ogscript

    Posted 07-13-2015 15:54

    Hi Bruno.

    ogScript uses JavaScript under the hood so you have access to the full set of string split/join/trim/compare functions you would have access to for JavaScript.

    To split a string into an array based on a comma, you would use:

    `

    var myArray = myString.split(',');

    `

    You could then iterate over that array to do whatever you want.

    `

    var myArray = params.getValue('String', 0).split(',');

    for (var i = 0; i < myArray.length; i++)

    {

    ogscript.debug('[' + i + ']: ' + myArray[i]);

    }

    `

    To learn more about the string functions you have access to, I recommend checking out w3Schools.

    w3Schools String Reference


    #DashBoard


  • 3.  RE: string parser with ogscript

    Posted 07-13-2015 16:59
    Thanks James

    Bruno

    #DashBoard