$SubRep: Difference between revisions

From m204wiki
Jump to navigation Jump to search
(Automatically generated page update)
(Automatically generated page update)
 
(23 intermediate revisions by 4 users not shown)
Line 2: Line 2:
<span class="pageSubtitle">Replace occurrences of string</span>
<span class="pageSubtitle">Replace occurrences of string</span>


<p class="warn"><b>Note: </b>Many $functions have been deprecated in favor of Object Oriented methods. The recommended OO replacement function for $SubRep is <var>[[Replace (String function)|Replace]]</var>. (See the [[#Usage notes|Usage notes]] below.) </p>


<span class="warning"><b>Note:</b></span> Most Sirius $functions have been deprecated in favor of Object Oriented methods. The recommended OO replacement function for $SubRep is <var>[[Replace (String function)|Replace]]</var>. (See the [[#Usage notes|Usage notes]] below.)
This function replaces occurrences of a substring in one string with another.
 
The <var>$SubRep</var> function accepts five arguments and returns a string result that is part of the first argument string.
 
==Syntax==
<p class="syntax"><span class="term">%string</span> = <span class="literal">$SubRep</span>(<span class="term">string</span>, <span class="term">substring</span>, <span class="term">repstring</span>, [<span class="term">start_pos</span>], [<span class="term">count</span>])
</p>
 
===Syntax terms===
<table>
<tr><th>%string</th>
<td>The part of the first argument string that remains after the replacements of <span class="term">substring</span> by <span class="term">repstring</span>.</td></tr>


<tr><th>string</th>
<td>An arbitrary string. </td></tr>


This function replaces occurrences of a substring in one string with another.  
<tr><th>substring</th>
<td>An arbitrary string located in the <var class="term">string</var> argument value. </td></tr>
 
<tr><th>repstring</th>
<td>A replacement string. </td></tr>


The <var>$SubRep</var> function accepts five arguments and returns a string result that is part of the first argument string.  
<tr><th>start_pos</th>
<td>A starting position in the <var class="term">string</var> argument string. This optional argument defaults to 1. </td></tr>


The first argument is an arbitrary string.  
<tr><th>count</th>
<td>A repeat count indicating the number of occurrences to be replaced. This optional argument defaults to 1. </td></tr>
</table>


The second argument is an arbitrary string located in argument 1.  
==Usage notes==
<ul>
<li>As stated above, the recommended OO replacement function for <var>$SubRep</var> is <var>[[Replace (String function)|Replace]]</var>. However, unlike <var>$SubRep</var>, <var>Replace</var> is Longstring capable (like all OO methods), so:
<ul>
<li>Both <var>$SubRep</var> and <var>Replace</var> have an optional argument for the count of substrings to replace, but their defaults differ: for <var>$SubRep</var> it is 1; <var>Replace</var> replaces all instances of the substring. </li>


The third argument is a replacement string.  
<li>It is possible that an application using <var>$SubRep</var> is unintentionally using "silent truncation," which will become noticable if you replace it with <var>Replace</var>; see the discussion in [[Longstrings]]. </li>


The fourth argument is a starting position in the first argument string. This is an optional argument and defaults to 1.  
<li>'''Do not''' replace <var>Replace</var> with <var>$SubRep</var>. </li>
</ul> </li>


The fifth argument is a repeat count indicating the number of occurrences to be replaced. This is an optional argument, and it defaults to 1.
<li>If the substitution would cause the result value to exceed 255 characters, it is not performed. </li>
</ul>


==Syntax==
<p class="syntax"><span class="term">%STRING</span> = <span class="literal">$SubRep</span>(string, substring, repstring, -
start_pos, count)
</p>
<p>
</p>
<p>%STRING is part of the first argument string.</p>
==Examples==
==Examples==
For example, this statement sets %JUNK to <tt>XYCDABAB</tt>:
<ol>
<li>This statement sets %JUNK to <code>XYCDABAB</code>:


<p class="code"> %JUNK = $SubRep('ABCDABAB', 'AB', 'XY')
<p class="code">%JUNK = $SubRep('ABCDABAB', 'AB', 'XY')
</p>
</p>


This statement sets %JUNK to <tt>XYCDXYXY</tt>:
<li>This statement sets %JUNK to <code>XYCDXYXY</code>:
<p class="code"> %JUNK = $SubRep('ABCDABAB', 'AB', 'XY', ,5)
<p class="code">%JUNK = $SubRep('ABCDABAB', 'AB', 'XY', ,5)
</p>
</p>


This statement sets %JUNK to <tt>ABCDXYXY</tt>.
<li>This statement sets %JUNK to <code>ABCDXYXY</code>.
<p class="code"> %JUNK = $SubRep('ABCDABAB', 'AB', 'XY', 3 ,5)
<p class="code">%JUNK = $SubRep('ABCDABAB', 'AB', 'XY', 3 ,5)
</p>
</p>
</ol>


If the substitution would cause the result value to exceed 255 characters, it is not performed.
==<b id="auth"></b>Products authorizing {{PAGENAMEE}}==  
 
==Usage notes==
As stated above, the recommended OO replacement function for <var>$SubRep</var> is <var>[[Replace (String function)|Replace]]</var>. However, unlike <var>$SubRep</var>, <var>Replace</var> is Longstring capable (like all OO methods), so:
<ul>
<li>Both <var>$SubRep</var> and <var>Replace</var> have an optional argument for the count of substrings to replace, but their defaults differ: for <var>$SubRep</var> it is 1; <var>Replace</var> replaces all instances of the substring.
<li>It is possible that an application using <var>$SubRep</var> is unintentionally using "silent truncation," which will become noticable if you replace it with <var>Replace</var>; see the discussion in [[Longstrings|"Longstrings"]].
<li>'''Do not''' replace <var>Replace</var> with <var>$SubRep</var>.
</ul>
 
==See also==
==Products authorizing {{PAGENAMEE}}==  
<ul class="smallAndTightList">
<ul class="smallAndTightList">
<li>[[Sirius functions]]</li>
<li>[[List of $functions|Sirius functions]]</li>
<li>[[Fast/Unload User Language Interface]]</li>
<li>[[Fast/Unload User Language Interface]]</li>
<li>[[Janus Open Client]]</li>
<li>[[Media:JoclrNew.pdf|Janus Open Client]]</li>
<li>[[Janus Open Server]]</li>
<li>[[Media:JosrvrNew.pdf|Janus Open Server]]</li>
<li>[[Janus Sockets]]</li>
<li>[[Janus Sockets]]</li>
<li>[[Janus Web Server]]</li>
<li>[[Janus Web Server]]</li>
<li>[[Japanese functions]]</li>
<li>Japanese functions</li>
<li>[[Sir2000 Field Migration Facility]]</li>
<li>[[Media:SirfieldNew.pdf|Sir2000 Field Migration Facility]]</li>
</ul>
</ul>
<p>
 
</p>


[[Category:$Functions|$SubRep]]
[[Category:$Functions|$SubRep]]

Latest revision as of 23:29, 20 September 2018

Replace occurrences of string

Note: Many $functions have been deprecated in favor of Object Oriented methods. The recommended OO replacement function for $SubRep is Replace. (See the Usage notes below.)

This function replaces occurrences of a substring in one string with another.

The $SubRep function accepts five arguments and returns a string result that is part of the first argument string.

Syntax

%string = $SubRep(string, substring, repstring, [start_pos], [count])

Syntax terms

%string The part of the first argument string that remains after the replacements of substring by repstring.
string An arbitrary string.
substring An arbitrary string located in the string argument value.
repstring A replacement string.
start_pos A starting position in the string argument string. This optional argument defaults to 1.
count A repeat count indicating the number of occurrences to be replaced. This optional argument defaults to 1.

Usage notes

  • As stated above, the recommended OO replacement function for $SubRep is Replace. However, unlike $SubRep, Replace is Longstring capable (like all OO methods), so:
    • Both $SubRep and Replace have an optional argument for the count of substrings to replace, but their defaults differ: for $SubRep it is 1; Replace replaces all instances of the substring.
    • It is possible that an application using $SubRep is unintentionally using "silent truncation," which will become noticable if you replace it with Replace; see the discussion in Longstrings.
    • Do not replace Replace with $SubRep.
  • If the substitution would cause the result value to exceed 255 characters, it is not performed.

Examples

  1. This statement sets %JUNK to XYCDABAB:

    %JUNK = $SubRep('ABCDABAB', 'AB', 'XY')

  2. This statement sets %JUNK to XYCDXYXY:

    %JUNK = $SubRep('ABCDABAB', 'AB', 'XY', ,5)

  3. This statement sets %JUNK to ABCDXYXY.

    %JUNK = $SubRep('ABCDABAB', 'AB', 'XY', 3 ,5)

Products authorizing $SubRep