I'm afraid I have to disagree with you, Fernando.  The DO WHILE approach may 
not be optimal, but it does work.  If you have three consecutive commas, for 
instance, the first two get changed to one comma on the first loop, leaving two 
consecutive commas.  On the second loop, those are changed to one comma.  
Honest, the process works fine and executes very quickly in VFP.  It's much 
faster than having to test each and every array element to see if it is empty.

Mike



-----Original Message-----
From: ProfoxTech [mailto:[email protected]] On Behalf Of Fernando D. 
Bozzo
Sent: Thursday, July 28, 2016 6:07 PM
To: [email protected]
Subject: Re: Bad getwordnum

The "DO WHILE" approach is not optimal, not even exact, because you can have 
more than 2 consecutive commas.

One optimal and exact approach is using ALINES() indicating the comma as the 
separator and using the optional parameters to take out empty parameters, so 
the final array have only non-empty values.
In the case that you want empty values too, then do not use the optional 
parameters of ALINES().




2016-07-28 23:47 GMT+02:00 Michael Glassman <[email protected]>:

> So just make sure there are no consecutive commas first:
> DO WHILE ",," $ cStr
> cStr = strtran(cStr, ",,", ",")
> END DO
>
> Mike
>
>
>
> -----Original Message-----
> From: ProfoxTech [mailto:[email protected]] On Behalf Of 
> Fred Taylor
> Sent: Thursday, July 28, 2016 3:25 PM
> To: [email protected]
> Subject: Re: Bad getwordnum
>
> The problem lies with consecutive commas.  If you put a space between 
> the commas after the 2 and before the one in front of the 3, it works OK.
>
> ?GETWORDCOUNT("1,2, ,3")  && prints 4
> ?GETWORDNUM("1,2, ,3",1,",")  && prints "1"
> ?GETWORDNUM("1,2, ,3",2,",")  && prints "2"
> ?GETWORDNUM("1,2, ,3",3,",")  && prints " "
> ?GETWORDNUM("1,2, ,3",4,",")  && prints "3"
>
> Fred
>
> On Thu, Jul 28, 2016 at 12:31 PM, Darren <[email protected]> wrote:
>
> > I am cautious of using getwordnum() for following reason.
> >
> > Given:
> >
> > lcString = "1,2,,3"
> >
> > My observation is there are 4 separate words in that string using 
> > the comma as a separator - albeit one is null
> >
> > ? GETWORDCOUNT(m.lcString,",")  - returns 3
> > ? OCCURS(",", m.lcString) + 1               - returns 4
> > ? ALINES(laLines, m.lcString, 3, ",")       - returns 4
> >
> > Guess it comes down to what a word is defined as.
> >
> >
> >
> > -----Original Message-----
> > From: ProfoxTech [mailto:[email protected]] On Behalf Of 
> > Stephen Russell
> > Sent: Friday, 29 July 2016 4:44 AM
> > To: [email protected]
> > Subject: Re: Bad getwordnum
> >
> > Sorry Fred they were considered words when it was a numeric value 
> > when loaded in the array.  We were extracting notes and there were 
> > addresses and times in there that muddied the waters.
> >
> > On Thu, Jul 28, 2016 at 11:44 AM, Fred Taylor <[email protected]>
> wrote:
> >
> > > Hi Stephen,
> > >
> > > Got an example where numbers aren't considered words in GETWORDNUM()?
> > >
> > > Seems to work fine for me.
> > >
> > > Fred
> > >
> > > On Thu, Jul 28, 2016 at 6:59 AM, Stephen Russell 
> > > <[email protected]>
> > > wrote:
> > >
> > > > I got burned by this a long time ago in that numbers are not 
> > > > considered words and we had sets of addresses in our document.
> > > >
> > > > Just giving you a heads up.
> > > >
> > > > On Tue, Jul 26, 2016 at 5:00 AM, Claudio <[email protected]>
> wrote:
> > > >
> > > > >
> > > > > > ----- Original Message -----
> > > > > >
> > > > > > Instead of using Getwordnum, split the string in an array 
> > > > > > using
> > > > > > ALINES(yourarray,yourstring,3,',')
> > > > > >
> > > > > > You can then access to each word, even if it's a null string.
> > > > > >
> > > > > > Gérard.
> > > > > >
[excessive quoting removed by server]

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to