method pattern.replace_string_segments
Contract
Return typewob
Parameter keyDefault valueType
a_stringreqstring
returns"first"type.<one_of "first" "last" "all"/>
Parameter kindDefault valueType
Other unkeyed argumentsreq with ekind of expressionwob
Water Contract
<method pattern.replace_string_segments
  a_string=req=string
  returns ="first"=<type.one_of "first" "last" "all"/>
  _other_unkeyed=req=wob=ekind.expression="_body"/>

See also: get_string_segments

Uses a pattern an its subpatterns to match string segments in an input string that are to be replaced.

a wob
Parameter keyDefault valueType
_subjectfalse
A pattern to find in the input string. The pattern will usually have sub-patterns, some of which are named.

a wob
Parameter keyDefault valueType
a_stringreqstring
The input string to find matches in.

a wob
Parameter keyDefault valueType
returns"first"type.<one_of "first" "last" "all"/>
How much of the input string to match. See get_string_segment for a description of "first", "last" and "all".

Below we have the input string of "frontazzzmiddlebzzzend". We have specified a pattern that can find "azzz" and "bzzz". For each of those patterns, the code in the content of the replace_string_segments call, ie "pre".<join prefix.<to_uppercase/> "post"/> is executed in an environment with the local variable prefix having the value of "a" for the first match of the pattern and "b" for the second match of the pattern. So for the first match, the code returns "preApost" and for the seond match it returns "preBpost". These computed strings replace the substring that was matched, so the output string, "frontpreApostmiddlepreBpostend" is the same as the input string except that "azzz" has been replaced with "preApost" and "bzzz" has been replaced with "preBpost".
<pattern pattern.<named "prefix" pattern.<one_of "a" "b"/>/>  "zzz"/>.
    <replace_string_segments "frontazzzmiddlebzzzend" returns="all">
      "pre".<join prefix.<to_uppercase/> "post"/>
  </>
"frontpreApostmiddlepreBpostend"
replace_string_segments is a powerful string transformation tool. Note that the named patterns to match and make into local variables must be immediate sub-patterns of the _subject pattern.