Using length differences only works when counting a character or string of 
characters. It does not work when counting words. In Keith’s example “Time” as 
a word does not exist in the text passed to $a. “The” is another example as it 
only occurs twice, but the code will return 3.

John

> On May 5, 2017, at 9:05 AM, Keith Culotta via 4D_Tech <4d_tech@lists.4d.com> 
> wrote:
> 
> I haven't tested this for speed or unexpected conditions, but...
> 
> $a:="now is the timetime for all good men to come to the aid of their country"
> $l1:=Length($a)
> 
> $b:="time"
> $lb:=Length($b)
> 
> $a:=Replace string($a;$b;"";*)
> $l2:=Length($a)
> 
> $l3:=$l1-$l2/$lb
> 
> ALERT(String($l3))
> 
> 
> Keith - CDI
> 
>> On May 4, 2017, at 7:22 AM, Jörg Knebel via 4D_Tech <4d_tech@lists.4d.com> 
>> wrote:
>> 
>> Hi all
>> 
>> I’m wondering if someone has a clever routine to count the number of 
>> appearances of a specific character/word in a string/text and is willing to 
>> share it.
>> 
>> Thanks
>> 
>> Cheers
>> Jörg
>> 
>> 
>> **********************************************************************
>> 4D Internet Users Group (4D iNUG)
>> FAQ:  http://lists.4d.com/faqnug.html
>> Archive:  http://lists.4d.com/archives.html
>> Options: http://lists.4d.com/mailman/options/4d_tech
>> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
>> **********************************************************************
> 
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **********************************************************************

**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**********************************************************************

Reply via email to