Hitachi Vantara Pentaho Community Forums
Results 1 to 5 of 5

Thread: charAt() not working

  1. #1
    Join Date
    Jun 2008
    Posts
    14

    Question charAt() not working

    Hello All

    I'm trying to get a single character value from a string using charAt() in a modified JavaScript Value. Instead of getting a single character I'm getting a number. Any ideas?

    Offending files attached.

    Cheers
    Kyle
    Attached Files Attached Files

  2. #2
    Join Date
    May 2006
    Posts
    4,882

    Default

    Try:

    Code:
    s1.substring(0, 1);
    or

    Code:
    String(s1).charAt(0));
    to get at the first character of a string.

    Regards,
    Sven

  3. #3
    Join Date
    Jun 2008
    Posts
    14

    Default

    Hi Sven

    I've got the substring() to work. Not sure why the charAt() is throwing up spurious results but there always appears to be more than one way to do what's required in Spoon

    Cheers
    Kyle

  4. #4
    Join Date
    May 2006
    Posts
    4,882

    Default

    It's something to do with the javascript/java integration... in your original case you get the value of the character back (instead of the actual character), so probably somewhere a conversion to integer is happening.

    Using my second piece of code (explicitly casting to a javascript string) also works.

    Regards,
    Sven

  5. #5
    Join Date
    Jun 2008
    Posts
    14

    Default

    Hi Sven

    I thought that must be what was happening (getting the value rather than the actual character). Just a bit frustrating but we have a workaround. :-)

    Cheers
    Kyle

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.