cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Substring not working

ATT1405
11-Garnet

Substring not working

I am trying to extract the data from big string (ASCII)  40 char long into 10 word

following code does not work.

I am trying to test service in Thing Template

 

var rawString = me.vbsMachineRawData;
var rawHexWord = [];
var j = 0;

for (var i = 0; 40 ; 4) {
rawHexWord[j] = rawString.substring(i, (i + 4));
j = j + 2;
}

error executing service

 

ACCEPTED SOLUTION

Accepted Solutions

var rawString = '1111111111111111111111111111111111111111';
var rawHexWord = [];
for (var i = 0; i < 40 ; ) {
    rawHexWord.push( rawString.substring(i, (i + 4)));
    i = i + 4;
}
result = rawHexWord; // Result will be 
 - ["1111","1111","1111","1111","1111","1111","1111","1111","1111","1111"]

Try above snippet

View solution in original post

2 REPLIES 2

var rawString = '1111111111111111111111111111111111111111';
var rawHexWord = [];
for (var i = 0; i < 40 ; ) {
    rawHexWord.push( rawString.substring(i, (i + 4)));
    i = i + 4;
}
result = rawHexWord; // Result will be 
 - ["1111","1111","1111","1111","1111","1111","1111","1111","1111","1111"]

Try above snippet

Satish,

thanks. That works.

 

Announcements


Top Tags