SubstituteRange ( text; beginString; endString; replaceString )
Rate this function: Average rating: 3.7 (16 votes) Discuss this Custom Function
Jim Main, Main Solutions
http://www.mainsolutions.org
Replaces all occurrances of two text strings, along with any text between them, with another value
Sample Input:
SubstituteRange ( text; "<SPAN"; ">"; "" )
where the content of text is:
<SPAN STYLE= "font-size: 14px;" >size14text </SPAN>
<SPAN STYLE= "color: #3333CC;" >bluetext </SPAN>
<SPAN STYLE= "font-weight: bold;" >boldtext </SPAN>
|
|
Sample Output:
size14text </SPAN> bluetext </SPAN> boldtext </SPAN>
|
|
Description:
This is equivalent to the 'Substitute' function, with a single wilcard value. It replaces every occurrance in 'text' of 'beginString*endString', with 'replaceString' (where '*' is any text value of any length). Each beginString value is replaced beggining with the first, up to the first endString value encountered. Each subsequent remaining beginString is processed, until no trailing endString is found.
For example, if beginString = "<tr>", endString = "</tr>" and replaceString = "-", the following text would generate the following results:
a<tr>b<tr>c</tr>d</tr>e
a-d</tr>e
a<tr>b</tr>c<tr>d</tr>e
a-c-e
a</tr>b<tr>c</tr>d<tr>e
a</tr>b-d<tr>e
I've wanted this feature for some time to parse html tags. However, as there is no way to remove text formatting in FM7 (such as size, font, and color) I've also found it useful in conjunction with the 'GetAsCSS' function to remove field formatting. The following formula will remove all formatting from any text field:
SubstituteRange(
Substitute(GetAsCSS (Field), "</SPAN>¶", "")
, "<SPAN"; ">"; "" )
It uses a combination of html and URL-encoding for special characters that you'll need to substitute for (a return (¶) generates <BR>, while an ampersand (&) generates &amp;)
Note: these functions are not guaranteed
or supported by BrianDunning.com. Please contact the individual
developer with any questions or problems.
This is my Custom Function and I want to
edit it
Discuss:Make a comment about this Custom Function (please try to keep it brief & to the point). Anyone can post:
|
Newest Custom Functions:
| 1. |
list.intersect (listA; listB) |
| |
(Mon, May 14, 12:43pm) |
| 2. |
WeekStart ( weekOfYear ; year ) |
| |
(Sat, May 12, 8:42am) |
| 3. |
PercentToWords (FIELD) |
| |
(Thu, May 10, 3:16pm) |
| 4. |
PercentToText (FIELD) |
| |
(Thu, May 10, 2:37pm) |
| 5. |
StripReserved( text ) |
| |
(Wed, May 02, 6:05pm) |
| 6. |
ListBaseTables |
| |
(Wed, May 02, 3:48pm) |
| 7. |
ValidEmail( theEmail ) |
| |
(Wed, May 02, 7:27am) |
| 8. |
UltraDate (Text; LongDate_or_DateDigit) |
| |
(Wed, May 02, 6:07am) |
 |
|
This is a great custom function. However, there is a omission bug in the above code. This line here:
modText &
SubstituteRange(remainText; beginString; endString; replaceString)
should be
modText & replaceString &
SubstituteRange(remainText; beginString; endString; replaceString)
Otherwise, the replaceString is simply removed and nothing inserted.
Ron Smith, Fayetteville
April 11, 2009 2:38pm