String to char array

Former Member
Former Member
How I can convert to char array my string on old devices. This is not work :(
var teststring="Hello";

var stringArray = teststring.toCharArray();
  • Try:
    var teststring="Hello";

    var stringArray = teststring.toCharArray();

    as teststring is an array in your code and not a string.

    or do:
    var stringArray = teststring[0].toCharArray();

    and use the sting in the array.
  • It looks like Jim's comments were invalidated by the changes you made to your code after his post.

    The String.toCharArray() method was added in ConnectIQ 1.3.0. It is possible, but not likely, that the device you are testing on has firmware that doesn't have support for ConnectIQ 1.3.0. If this is the case, you might just need to update the device firmware. If you really need to support devices with out-of-date firmware, you should note that prior to ConnectIQ 1.3.0, the Lang.Char type didn't exist, and the only way to explode a string was to make a bunch of single character strings, like this...

    // assumes `s' is composed of single-byte characters. returns an array
    // such that each character in `s' is stored as a string in the same
    // position in the result.
    function toCharArray(s) {
    var a = new [ s.length() ];
    for (var i = 0; i < s.length(); ++i) {
    a= s.substring(i, i+1);
    }
    return a;
    }
    [/code]
  • ...
    It is possible, but not likely, that the device you are testing on has firmware that doesn't have support for ConnectIQ 1.3.0.
    ...


    could be he's finding out the joys of developing for the Epix!