Visokio website     Downloads     Video tutorials     KnowledgeBase  
Scripting: extracting specific token in text string? - Visokio Forums
Scripting: extracting specific token in text string?
  •     naruemon November 26, 2012 4:13AM
    Hi,

    I have the data like the following:
    -----------------------
    index information
    1 A,B,C
    2 A,B,C
    3 A,B,C
    -----------------------

    Is that possible to get the data in specific token using the separator ','?
    The expected result is:
    -----------------------
    index information
    1 A
    2 B
    3 C
    -----------------------

    I tried with SCRIPT function but get the error 'sun.org.mozilla.javascript.internal.InterpretedFunction@554eef31'

    ------------------------------
    SCRIPT("
    function getToken(sVal, iIndex, sDelimiter)
    {

    if (sDelimiter.length > 0)
    {
    var aSubString = new Array();
    aSubString = sVal.split(sDelimiter);


    if (iIndex > aSubString.length
    || iIndex < 1)
    {
    return null ;
    }
    else
    {
    return aSubString[iIndex - 1]
    }

    }
    else
    {
    return null ;
    }

    }
    "


    , "sVal", [information], "iIndex", [index], "sDelimiter", ",", 50)
    ------------------------------

    Please kindly suggest. Thank you.

    Omniscope v.2.8 build 414
  • 2 Comments
  •     steve November 26, 2012 4:58AM
    You have only defined a function, and not called it. The result of your Javascript is the function itself. For example:

    function a(x, y) {
    return x*y;
    }

    Here the result has type Function and is the function object itself. Within browser-based JS, you might pass this to event handlers, for example, but as a return value for the SCRIPT function, it's of no use.

    Instead you need to ensure the *last* expression in the JS is the desired result. For example:

    function a(x, y) {
    return x*y;
    }
    /* here, any other code, irrelevant to result */
    a(2,3); // result expression

    ... yields 6.

  •     naruemon November 28, 2012 10:52AM
    many thanks for your suggestion ^^

Welcome!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

Tagged