The following function removes characters from a string by looking for the search string with the $ operator and replacing it with nothing.

? strip( "banana", "an" ) // Displays "ba"

function strip( cArg, cStrip )

   local cRet, nLen 

   cRet = cArg 

   nLen = len( cStrip ) 

   do while cStrip $ cRet 

      cRet := stuff( cRet, at( cStrip, cRet ), nLen, "" ) 

   enddo 

return cRet 

All the loop needs know is whether the substring is in the main string, not where it is, so the $ operator is slightly more convenient that using the AT( ) function. If the substring is in the main string, then STUFF( ) is used to remove it, using the position returned by AT( ). The length of the substring is stored in a variable before the loop; it never changes so there’s no need to get it repeatedly in the loop.