Hitachi Vantara Pentaho Community Forums
Results 1 to 4 of 4

Thread: Replace function in Modified JavaScript step

  1. #1
    Join Date
    Jul 2007
    Posts
    247

    Default Replace function in Modified JavaScript step

    Hi everybody,

    I have a question concerning the replace function in the modified javascript step. How does one replace characters like "* $ {" ???

    If I change the sample from the step into this (by changing the word "nice" to "* ${") ...

    Code:
    // Replaces Strings inside the given Variable.
    // It is possible to make more replacements inside
    // one call. The given variables must be an odd number
    //
    // Usage:
    // replace(var, var, var);
    // 1: String - The Variable with the content to replace.
    // 2: String - The Value to search for.
    // 3: String - The Value to replace with.
    //
    // replace(var, var, var, var,var,...)
    // 1: String - The Variable with the content to replace.
    // 2: String - The First Value to search for.
    // 3: String - The First Value to replace with.
    // 4: String - The Second Value to search for.
    // 5: String - The Second Value to replace with.
    // ...
    //
    // 2006-11-15
    //
    var str1 = "Hello World, this is a * ${ function";      
    var str2 = replace(str1,"World", "Folk");
    Alert(str2);
    var str2 = replace(str1,"World", "Folk", "* ${","beautifull");
    Alert(str2);
    ... I'll get the following error: "org.mozilla.javascript.EvaluatorException: The function call replace is not valid (script#24)"

    Just copy & paste my code and hit the "Test Script" button to reproduce it. Is there a special syntax one has to use?

    I'm using PDI 2.52.


    Thx in advance,
    Ben

  2. #2
    Join Date
    Nov 1999
    Posts
    9,729

    Default

    Code:
    var str1 = "Hello World, this is a * ${ function";      
    var str2 = replace(str1,"World", "Folk");
    Alert(str2);
    var str2 = replace(str1,"World", "Folk", "\\* \\$\\{", "beautifull");
    Alert(str2);

  3. #3
    Join Date
    Nov 1999
    Posts
    9,729

    Default

    Beautiful isn't it?

  4. #4
    Join Date
    Jul 2007
    Posts
    247

    Default

    Beautiful, indeed . I should have thought of it...

    Thx for the quick reply.


    Regards,
    Ben

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.