Groups > dBase > dBase shared code > Re: stipchar function fix in stringex.cc




Re: stipchar function fix in stringex.cc

Re: stipchar function fix in stringex.cc
Wed, 14 Mar 2007 13:18:07 -040
Hi,

I'm trying to incorporate this program into changing a field in a database.

Before function I put the following to set up the variables:
use webtest &&database
cstrarg=testdate && fieldname
cstrip="-" && take out dashes
lword=.f.

It runs but does not change the testdate to the end result withouth the 
dashes.

What am I doing wrong?

Thanks,Lorna

"Howard Mintzer" <hmintzerNOSPAM@optonline.net> wrote in message

news:Ryjjg%23$MFHA.1528@news-server...
> There was a bug in function stripchar. If you added the lword=true 
> parameter (that commads the function to remove an entire 'phrase' from the

> input string) only the first instance of the phrase was removed. Say 
> cStrArg='abcd<b>ef<b>gh' .
> If you did this stripChar(cStrArg,'<b>',false) the result was
'acdefgh'
> If you did this stripChar(cStrArg,'<b>',true) the result was
'abcdef<b>gh' 
> wherease you expected 'abcdefgh'. The new code as follows fixes the 
> problem and the function works as originally described.
>
>   FUNCTION StripChar( cStrArg, cStrip, lWord )
>   /*
>      -----------------------------------------------------------------
>      Programmer..: Steve Saville
>      Date........: January 15, 2002
>      Notes.......: Strips selected character(s) out of alphanumeric
>                    string (like perhaps, removing hyphens from a
>                    vehicle tag number: C-123-456 would become C123456)
>                    (uppercase/lowercase doesn't matter)
>      Written for.: dB2K
>      Rev. History: 01/15/2002 -- Copied StripND and modified to remove
>                    any character(s) included in the second parameter
>                    03/27/2005 -- Modified by Howard Mintzer to fix bug
>                    in program where setting lword to true only stripped
>                    the first instnace of cStrip from sStrArg. Now loops
>                    through cStrArg and removes all instances of phrase
>                    cStrip
>      Calls.......: None
>      Usage.......: stringex.StripChar(<cStrArg>,<cStrip>)
>      Example.....: ?
_app.String.StripChar("C-123-456","C-",false)
>                    Result: "123456"
>                   
?_app.string.stripchar("JustATestString","Test",false)
>                    Result: "JuAring"
>                   
?_app.string.stripchar("JustATestString","Test",true)
>                    Result: "JustAString"
>      Returns.....: character string stripped of desired character(s)
>      Parameters..: cStrArg = Character memvar containing alphanumeric
>                              string
>                    cStrip  = Character(s) to strip from cStrArg
>                    lWord   = If true, strips the exact word or phrase
>                              providing an exact match is found in
>                              cStrArg. If false, strips every character
>                              which has a match from cStrArg
>     ------------------------------------------------------------------
>   */
>
>   local cRetVal, nCount, cChar
>      cRetVal = ""
>      if lWord = false
>            for nCount = 1 to len( cStrArg )
>                  cChar = substr(cStrArg,nCount,1)
>                  if not upper(cChar) $upper(cStrip)
>                     cRetVal = cRetVal+cChar
>                  endif
>            endfor
>         else
>          do while at(upper(cStrip),upper(cStrArg))>0
>           cStrArg=left(cStrArg,at(upper(cStrip),upper(cStrArg)) -1)+;
>           right(cStrArg,(len(cStrArg) - at(upper(cStrip),;
>           upper(cStrArg)) - len(cStrip) + 1))
>          enddo
>          cRetVal=cStrArg
>        endif
>
> //    the original code follows...this only removed the first instance of 
> cStrip
> //         else
> //            cRetVal = iif(at(upper(cStrip),upper(cStrArg)) = 0,cStrArg,;
> //            left(cStrArg,at(upper(cStrip),upper(cStrArg)) -1)+;
> //            right(cStrArg,(len(cStrArg) - at(upper(cStrip),;
> //            upper(cStrArg)) - len(cStrip) + 1)))
> //         endif
>
>
>
>   RETURN cRetVal
>   // EoM: StripChar() 

Post Reply
Re: stipchar function fix in stringex.cc
Wed, 14 Mar 2007 21:58:24 +020
On Wed, 14 Mar 2007 19:18:07 +0200, lorna walsh <lwalsh@necc.mass.edu>  
wrote:

> Hi,
>
> I'm trying to incorporate this program into changing a field in a  
> database.
>
> Before function I put the following to set up the variables:
> use webtest &&database
> cstrarg=testdate && fieldname
> cstrip="-" && take out dashes
> lword=.f.
>
> It runs but does not change the testdate to the end result withouth the
> dashes.
>
> What am I doing wrong?
>

Try the following.  (I have commented out the database references and hard  
coded a date as I don't have the database available.)

set procedure to stringex.cc additive
oMyString = new StringEx()
//use webtest &&database
//cstrarg=testdate && fieldname
cstrarg = "23-03-2007"
cstrip="-" && take out dashes
lword=.f.
cstrarg = oMystring.stripchar(cstrarg,cstrip,lword)
? cstrarg
// replace testdate with cstrarg && If this is what you want.


This is not actually the proper newsgroup for this sort of query.  If you  
still have problems getting this to work, I suggest you take this further  
in the Programming newsgroup.  Don't let posting a query in the wrong  
newsgroup worry you though as no harm has been done but this newsgroup is  
for sharing chunks of code that actually work rather than for sorting out  
problems.  You'll probably get a better response from the Programming  
newsgroup as well.

Mervyn.


Post Reply
Re: stipchar function fix in stringex.cc
Thu, 15 Mar 2007 11:23:38 -040
Sorry, will do.

Lorna
"Mervyn Bick" <invalid@invalid.invalid> wrote in message 
news:op.to623mm1380wm4@mervyn1...
On Wed, 14 Mar 2007 19:18:07 +0200, lorna walsh <lwalsh@necc.mass.edu>
wrote:

> Hi,
>
> I'm trying to incorporate this program into changing a field in a 
> database.
>
> Before function I put the following to set up the variables:
> use webtest &&database
> cstrarg=testdate && fieldname
> cstrip="-" && take out dashes
> lword=.f.
>
> It runs but does not change the testdate to the end result withouth the
> dashes.
>
> What am I doing wrong?
>

Try the following.  (I have commented out the database references and hard
coded a date as I don't have the database available.)

set procedure to stringex.cc additive
oMyString = new StringEx()
//use webtest &&database
//cstrarg=testdate && fieldname
cstrarg = "23-03-2007"
cstrip="-" && take out dashes
lword=.f.
cstrarg = oMystring.stripchar(cstrarg,cstrip,lword)
? cstrarg
// replace testdate with cstrarg && If this is what you want.


This is not actually the proper newsgroup for this sort of query.  If you
still have problems getting this to work, I suggest you take this further
in the Programming newsgroup.  Don't let posting a query in the wrong
newsgroup worry you though as no harm has been done but this newsgroup is
for sharing chunks of code that actually work rather than for sorting out
problems.  You'll probably get a better response from the Programming
newsgroup as well.

Mervyn.



Post Reply
about | contact