Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

unable to extract substring from string in javascript evaluator

I am trying to extract data from the string i use index and substring function in java script to find the value.

var str = "May 21 16:00:03 localhost TM:78 2018-05-21 16:00:03 [HIP:239839484][PDU_TYPE:bfjbhfwjb][URL_TYPE:3][UUID : c21d8dd6-cc12-40f2-963b-5e732f9e2337][SVC : yunuyye][PASS : null][TO : 978][SMS_COUNT : 1][DATA_CODING : 0][IS_SHORT:true][FROM : tonwork][TON : 5][NPI : 0][ESM_CLASS : 64][DLR : 1][SM_LEN : 159][CIP : null][VP:null][ACT:null][DEST:786][X-Mannel-smppbox-submit_sm.meta-dataSmsPlus2||-||214||-||WorkXI||-||46||-||etisalat||-||0.01180||-||0.01560||-||0.01200||-||ytsrt_route||-||0.01030||-||-1|1187[TIME:6]";

var n = str.indexOf("Mannel");

var indexOfTimeStr = str.indexOf("TIME");

var res = str.substring(n,indexOfTimeStr-3);

document.write(res);

My desired Output:- image description

But while using in JS evaluator in streamsets I got this problem

image description

This is what I have tried in JS script

`var startIndex = records[i].value['text'].indexOf(records[i].value['text'],"Mannel");

var endIndex = records[i].value['text'].indexOf(records[i].value['text'],"TIME");

records[i].value['text']= records[i].value['text'].substring(records[i].value['text'],startIndex,endIndex-3);`

unable to extract substring from string in javascript evaluator

I am trying to extract data from the string i use index and substring function in java script to find the value.

var str = "May 21 16:00:03 localhost TM:78 2018-05-21 16:00:03 [HIP:239839484][PDU_TYPE:bfjbhfwjb][URL_TYPE:3][UUID : c21d8dd6-cc12-40f2-963b-5e732f9e2337][SVC : yunuyye][PASS : null][TO : 978][SMS_COUNT : 1][DATA_CODING : 0][IS_SHORT:true][FROM : tonwork][TON : 5][NPI : 0][ESM_CLASS : 64][DLR : 1][SM_LEN : 159][CIP : null][VP:null][ACT:null][DEST:786][X-Mannel-smppbox-submit_sm.meta-dataSmsPlus2||-||214||-||WorkXI||-||46||-||etisalat||-||0.01180||-||0.01560||-||0.01200||-||ytsrt_route||-||0.01030||-||-1|1187[TIME:6]"; 

var n = str.indexOf("Mannel");

str.indexOf("Mannel");

var indexOfTimeStr = str.indexOf("TIME");

str.indexOf("TIME");

var res = str.substring(n,indexOfTimeStr-3);

str.substring(n,indexOfTimeStr-3);

document.write(res);

document.write(res);

My desired Output:- image description

But while using in JS evaluator in streamsets I got this problem

image description

This is what I have tried in JS script

`var

var startIndex = records[i].value['text'].indexOf(records[i].value['text'],"Mannel");

records[i].value['text'].indexOf(records[i].value['text'],"Mannel");

var endIndex = records[i].value['text'].indexOf(records[i].value['text'],"TIME");

records[i].value['text'].indexOf(records[i].value['text'],"TIME");

records[i].value['text']= records[i].value['text'].substring(records[i].value['text'],startIndex,endIndex-3);`

records[i].value['text'].substring(records[i].value['text'],startIndex,endIndex-3);