Class: String
Description
This method provides a way to store information in a delimited string. Instead of identifying information by its position within the string, information is identified by a label. The position of the label within the string is irrelevant (and changing).
In its simplest form (with majorDelim and subDelim the same value), the String consists of label-value pairs. The information is stored in the piece immediately following the label. In this scenario, the position parameter value must be 1.
If majorDelim and subDelim are different, then subDelim separates the label from the information. In this scenario, position can specify an arbitrary positive integer value. Position 1 denotes the subfield immediately following the label; position 2 denotes a second subfield following the label; etc.
The method appends the labeled information to the end of the result. A previous occurrence of the label and its fields within the string will be removed.
Syntax
StringObject.putSub(String insert,String label,String majorDelim,
String subDelim, Number position)
Parameters
insert |
The string to insert. |
label |
The string used to label the field within the result. |
majorDelim |
The character or symbol that delimits fields within the result. |
subDelim |
The character or symbol that separates the label from the inserted string and other subfields associated with the label. If not specified, the default is the majorDelim value. |
position |
The subfield position at which to insert the string within the labeled field. If majorDelim and subDelim are the same value, position is 1. If not specified, the default is 1. |
Returns
A String.
When Became Available
v7.0
Example
type String STR = "L1#S11#S12;L2#S21#S22#S23;L3#S31"
// most general: "L1#S11#S12;L3#S31;L2#S21#S22#x98"
type String PUT = STR.putSub("x98","L2",";","#",3)
// pos defaults to 1: "L1#S11#S12;L3#S31;L2#xp1#S22#S23"
set PUT = STR.putSub("xp1","L2",";","#")
// example with major=sub: "L1;v1;L3;v3;L2;XXX"
type String SLP = "L1;v1;L2;v2;L3;v3"
set PUT = SLP.putSub("XXX","L2",";")
// two separators, but always 1 pair of label-values
type String DEL = "RTN=String;MODDAT=Number;DES=String"
set PUT = SLP.putSub("Date","MODDAT",";","=")