The CreatorCon Call for Content is officially open! Get started here.

Transform maps script

pvv1045330
Tera Contributor

Hi All,

I have my xlsx data like Number: 13456, 246892, 123,2456

 

but output like Number: CH013456,CH246892,CH000123,CH002456,some time we have 2or3 zero missing in the column,

 

I'm using the below code but it will not retrieve the all data, some data missing where column contains 6,4,3numbers. 

 

var numid = source.u_id.toString().trim() ;
    var size = 8;
    while(numid.length < size){
        numid = "0" + numid;
    }
    numid = "CI0" + numid ;
    
    return numid

                            

1 REPLY 1

Varun Sharma
Tera Expert

Hi There, 

 

Try parsing it using the regex operations, 

you can do it something like, 

 

var inputString = "Number: CH013456,CH246892,CH000123,CH002456,";

// Use regular expressions to extract integers following "CH"
var regex = /CH(\d+)/g;
var matches = [];
var match;

while ((match = regex.exec(inputString)) !== null) {
    matches.push(match[1]); // match[1] contains the captured integer
}

gs.print(matches)

 

here it's printing all the integers in Array/list. 

 

Hope it helps. 

 

Regards, 


Varun Sharma