$SubRep: Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 2: Line 2:
<span class="pageSubtitle"><section begin="desc" />Replace occurrences of string<section end="desc" /></span>
<span class="pageSubtitle"><section begin="desc" />Replace occurrences of string<section end="desc" /></span>


<p class="warning">Most Sirius $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for the $SubRep function is the [[Replace (String function)]].</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 <var>$SubRep</var> 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.  
This function replaces occurrences of a substring in one string with another.  
Line 25: Line 27:
</p>
</p>
<p class="caption">%STRING is part of the first argument string.</p>
<p class="caption">%STRING is part of the first argument string.</p>
 
==Examples==
For example, this statement sets %JUNK to <tt>XYCDABAB</tt>:
For example, this statement sets %JUNK to <tt>XYCDABAB</tt>:


Line 41: Line 43:
If the substitution would cause the result value to exceed 255 characters, it is not performed.
If the substitution would cause the result value to exceed 255 characters, it is not performed.


==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, by default <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]]".
<li>'''Do not''' replace <var>Replace</var> with <var>$SubRep</var>.
</ul>
==See also==
<ul class="smallAndTightList">
<ul class="smallAndTightList">
<li>[[Sirius functions]]</li>
<li>[[Sirius functions]]</li>

Revision as of 17:31, 28 April 2011

<section begin="desc" />Replace occurrences of string<section end="desc" />


Note: Most Sirius $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.

The first argument is an arbitrary string.

The second argument is an arbitrary string located in argument 1.

The third argument is a replacement string.

The fourth argument is a starting position in the first argument string. This is an optional argument and defaults to 1.

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.

Syntax

<section begin="syntax" /> %STRING = $SubRep(string, substring, repstring, - start_pos, count) <section end="syntax" />

$SubRep Function

%STRING is part of the first argument string.

Examples

For example, this statement sets %JUNK to XYCDABAB:

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

This statement sets %JUNK to XYCDXYXY:

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

This statement sets %JUNK to ABCDXYXY.

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

If the substitution would cause the result value to exceed 255 characters, it is not performed.

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, by default 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.

See also

Products authorizing $SubRep