$SubRep: Difference between revisions
Jump to navigation
Jump to search
(Automatically generated page update) |
m (→Usage notes) |
||
Line 37: | Line 37: | ||
<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: | <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> | <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>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> | ||
<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>. | <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> | ||
</ul> | |||
<li>If the substitution would cause the result value to exceed 255 characters, it is not performed. | <li>'''Do not''' replace <var>Replace</var> with <var>$SubRep</var>. </li> | ||
</ul> </li> | |||
<li>If the substitution would cause the result value to exceed 255 characters, it is not performed. </li> | |||
</ul> | </ul> | ||
Revision as of 23:00, 10 October 2014
Replace occurrences of string
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.
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
- 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)