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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! 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