OpenNTF.org - Strip (or Replace) Multiple ch
My Links (Not logged in)
Code Bin Search
 
Hosted by Prominic.NET
Rate This Code
5 - brilliant stuff
4 - very nice
3 - average
2 - needs work
1 - bad
   OpenNTF Code Bin
About This Code
Brief Description:
Strip (or Replace) Multiple characters easily with @ReplaceSubstring 
Rating:
Not Rated Yet 
Contributor:
Steven Chapman 
Category:
Lotus Formula 
Type:
String functions 
Notes Version:
R4.x, R5.x, R6.x 
Last Modified:
24 Mar 2003 
OpenNTF Disclaimer

All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.

Code / Description
REM "Recursively strip many characters from a string";

REM "Replace 'FldName' a field whose value needs to be stripped";
vStripField:=FldName;

REM "Enter each character that needs to be stripped, seperated as a list";
vL1:="~":"!":"@":"#":"$":"%":"^":"&":"*":"(":")";

REM "Shift list to left, dropping first element, and appending null string at end";
vL2:=@Subset(vL1; -(@Elements(vL1) -1)):"";

REM "Strip the string";
@ReplaceSubstring(vStripField; vL1; vL2);

Usage / Example
I've found myself trying to remove all kinds of different characters from input, by repeating the @ReplaceSubstring function multiple times, until I found out I could do this.

This method builds on the functionality that @ReplaceSubstring can take 2 lists as arguments, and works left to right.
By using this, and shifting the characters, we can replace all characters in the first list.
This works like this, in simpler terms-

vString:="ABC#DEF^";
@ReplaceSubstring(vString; "#":"^"; "^":"")

In that example, @ReplaceSubstring scans through the string the first time, replacing all "#" with "^". The second time, it scans the string again, and replaces all "^" (which some were originally "#"), and replaces them with "".
 Comments
Posted by Grant R Lindsay on 06/09/2003 02:30:40 PMVery inventive
I enjoy seeing the ideas that other developers come up with. Here is another approach, if all that is needed is to remove the unwanted characters: tRemoveThese := "!" : "@" : "#" : "$"; @ReplaceSubstring( "!A@S#D$F"; tRemoveThese; "" ) This will return: "ASDF" -- Grant
 Add your comment!