0 Members and 1 Guest are viewing this topic.

procedure substring(); var i, j: integer; s: string; what2inc: integer; caseSens: boolean; begin result:=''; // input what to be included in the result s:=par('include'); try what2inc:=strToInt(s) except // we also support the following values if s = 'none' then what2inc:=0 else if s = 'both' then what2inc:=3 else if s = '1+2' then what2inc:=3 else what2inc:=1; // by default we include only the first delimiter end; caseSens:=isTrue(par('case')); // find the delimiters s:=macroDequote(par(2)); if pars[0] = '' then i:=1 else i:=pos_(caseSens, pars[0], s); // we don' trim this, so you can use blank-space as delimiter if i = 0 then exit; j:=pos_(caseSens, pars[1], s, i+1); if j = 0 then j:=length(s)+1; // apply what2inc if what2inc and 1 = 0 then inc(i, length(pars[0])); if what2inc and 2 > 0 then INC(j, length(pars[1])); // end of the story result:=macroQuote(copy(s, i, j-i)); end; // substring

Follow members gave a thank to your post:rejettoFor this post, 1 member gave a thank you!