Subject Re: stripping a string of special characters
From Mervyn Bick <invalid@invalid.invalid>
Date Sat, 14 Aug 2021 10:52:57 +0200
Newsgroups dbase.getting-started

On 2021/08/14 09:34, Charlie wrote:
> Hi...  Is it possible to strip a string of certain characters?  for instance in the following string I would like to remove all &  and #.  Is this possible in dbase?
>
> lionel-82148 gb&w scale ps-1 boxcar #777
>
> Thanks for any help!
>

Very little isn't possible in dBASE. :-)

cStr = "lionel-82148 gb&w scale ps-1 boxcar #777"
cNewStr = strip_chars(cStr)
?cStr
?cNewStr

The function defaults to stripping  & and # characters but if you ever
need to strip other characters simply pass them as a parameter.

    cNewStr = stripChars(cStr,"&#@%")


function strip_chars(cStr,cToStrip)
    local cNew
    if argcount() = 1
       cToStrip = "&#"
    endif
    cNew = ""
       for n = 1 to len(cStr)
          cChar = substr(cStr,n,1)
          if not cChar$cToStrip
             cNew += cChar
          endif
       next
    return cNew


Mervyn.