1.2k questions

1.4k answers

361 comments

339 users

Categories

Sidebar
+1 vote
854 views
by michael-h-5027 (14.8k points)
My OBX-5 has a limit of 30 characters so I need to split up each OBX-5 into new OBX segments.

1 Answer

+1 vote

Create a custom mapping with something like this:

// match() will return an array of matches.

// .{1,30} matches any character (except for line terminators)
// {1,30} Quantifier — Matches between 1 and 30 times,
//   as many times as possible, giving back as needed (greedy)
// g modifier: global. All matches (don't return after first match)

// Change the 30 to whatever string limit size you want for each OBX-5

/*jshint regexp: false */
var obxArray = source.getNode("OBX-5").match(/.{1,30} |.{1,30}/g);
/*jshint regexp: true */

// If there is only one OBX then remove it so we can replace it with the new OBX segments
message.removeFirstNode('OBX');

var k = 0;
for (var i=0 ; i < obxArray.length ; i++) {
   k = i + 1;
   message.addChild('/', 'OBX');
   message.setNode('OBX[' + k + ']-1', k);
   message.setNode('OBX[' + k + ']-5', obxArray[i]);
}
 

by michael-h-5027 (14.8k points)
edited by michael-h-5027
by joshua-t-2800 (150 points)
Would this be the same if I wanted to break off the OBX segment after 30 characters and put it into a new segment type? I.E. looking to break off the second half and put it into an NTE segment, is this process the same, just changing the appropriate OBXs to NTEs?
...