View Single Post
  #2  
Old May 29th, 2018, 06:12 AM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Parse data to determine page and extract data

You could use the substr method to parse the values from your string:
Code:
// Your field here.
var field = Field('SLOT1');
var type = field.substr(0, 1);
switch (type) {
  case 'V':
    var code = field.substr(1, 3);
    break;
  case 'C':
    var code = field.substr(1, 2);
    var serviceCode = field.substr(3, 2);
    var mileage = field.substr(5, 6);
    var value = field.substr(11, 4);
    break;
}
Alternatively, you could use regular expressions to match the pattern:
Code:
// Your field here.
var field = Field('SLOT1');
var [type, code, serviceCode, mileage, value] = (field.match(/^(.)(.{2,3})(.{2})?(.{6})?(.{4})?$/) || [,'B']).slice(1);
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote