Re: Counting occurrences of specific characters In a document

2017-11-08 Thread Arnaud de Montard via 4D_Tech

> Le 9 nov. 2017 à 06:10, Kirk Brooks via 4D_Tech <4d_tech@lists.4d.com> a 
> écrit :
> 
> Kirk,
> One trick for counting the number of characters is :
> 
> $n:=length($text)
> $text:=replace string($text;$char;"")
> $n:=$n-length($text)
> 
> That will work for your text file.

I use this instead:
  $text:=replace string($text;$char;"";*)  //that so magic little star…

But *don't use* 'Replace string' with versions older than v15 R3 where it's 
been re written, guaranteed wheel of death (if not crash). With those versions, 
a Position(...;*) loop to count $char is much better. Some code here:


-- 
Arnaud de Montard 



**
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
**

Re: Counting occurrences of specific characters In a document

2017-11-08 Thread Timothy Penner via 4D_Tech
Maybe this will help:

http://kb.4d.com/assetid=76822


// UTIL_HowMany
C_TEXT($1) // input
C_TEXT($2) // count this
C_LONGINT($0)
If (Count parameters=2)
   $0:=(Length($1)-(Length(Replace string($1;$2;""/Length($2)
Else
   $0:=0
End if



Once the project method is saved as UTIL_HowMany it can be used like this:
$a:="test, test, test"

$b:=","
$num:=UTIL_HowMany($a;$b)




From: 4D_Tech <4d_tech-boun...@lists.4d.com> on behalf of Chip Scheide via 
4D_Tech <4d_tech@lists.4d.com>
Sent: Wednesday, November 8, 2017 9:17:02 PM
To: 4d_tech@lists.4d.com
Cc: Chip Scheide
Subject: Re: Counting occurrences of specific characters In a document

a cheat.. you will create 2 copies of the data.

$Start_size := length(Imported_Text)
$Removed:=replace string(Imported_Text;Char(13))
$Removed_Size:=$Start_Size - Length($Removed)

$Removed_Size = number of characters (returns) replaced

> Thank you Cannon,
>
> Progress indicator is not the only reason we need to know number of
> rows in advance.  However, your suggestion for using parse position
> and file size for process bars is intriguing and new to me.  I will
> investigate.
>
> Kirk
>
>> On Nov 8, 2017, at 7:11 PM, Cannon Smith via 4D_Tech
>> <4d_tech@lists.4d.com> wrote:
>>
>> If the only reason you need to know the number of rows beforehand is
>> to help in showing a progress indicator, you could use the file size
>> and current parse position instead
>>
>> --
>> Cannon Smith
>>
>>> On Nov 8, 2017, at 6:42 PM, rooftop99--- via 4D_Tech
>>> <4d_tech@lists.4d.com> wrote:
>>>
>>> We are working with large Excel documents which contain upwards of
>>> 750K rows and we need to import each row into a 4D application to
>>> create records.  In advance of the import process I would like to
>>> know how may rows to expect.
>>
>> **
>> 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
> **

Hell is other people
 Jean-Paul Sartre
**
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
**

Re: Counting occurrences of specific characters In a document

2017-11-08 Thread Chip Scheide via 4D_Tech
a cheat.. you will create 2 copies of the data.

$Start_size := length(Imported_Text)
$Removed:=replace string(Imported_Text;Char(13))
$Removed_Size:=$Start_Size - Length($Removed)

$Removed_Size = number of characters (returns) replaced

> Thank you Cannon,
> 
> Progress indicator is not the only reason we need to know number of 
> rows in advance.  However, your suggestion for using parse position 
> and file size for process bars is intriguing and new to me.  I will 
> investigate.
> 
> Kirk
> 
>> On Nov 8, 2017, at 7:11 PM, Cannon Smith via 4D_Tech 
>> <4d_tech@lists.4d.com> wrote:
>> 
>> If the only reason you need to know the number of rows beforehand is 
>> to help in showing a progress indicator, you could use the file size 
>> and current parse position instead
>> 
>> --
>> Cannon Smith
>> 
>>> On Nov 8, 2017, at 6:42 PM, rooftop99--- via 4D_Tech 
>>> <4d_tech@lists.4d.com> wrote:
>>> 
>>> We are working with large Excel documents which contain upwards of 
>>> 750K rows and we need to import each row into a 4D application to 
>>> create records.  In advance of the import process I would like to 
>>> know how may rows to expect.
>> 
>> **
>> 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
> **

Hell is other people 
 Jean-Paul Sartre
**
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
**

Re: Counting occurrences of specific characters In a document

2017-11-08 Thread Keisuke Miyako via 4D_Tech
sounds like you are mainly interested in text data.

you could try

https://github.com/miyako/4d-plugin-xlsxio

which converts XLSX to JSON.

for XLS this might work

https://github.com/miyako/4d-plugin-free-xl

miyako



**
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
**

Re: Counting occurrences of specific characters In a document

2017-11-08 Thread Kirk Brooks via 4D_Tech
Kirk,
One trick for counting the number of characters is :

$n:=length($text)
$text:=replace string($text;$char;"")
$n:=$n-length($text)


That will work for your text file.

Excel is more complicated. If it's .xls it's basically XML. Miyako made a
component for working with them that may work for you. Check out his github
site. You may be able to just parse the XML too, I haven't ever tried so
can't say for sure.


On Wed, Nov 8, 2017 at 5:42 PM, rooftop99--- via 4D_Tech <
4d_tech@lists.4d.com> wrote:

> What is the most efficient way to count the number of occurrences of a
> specific character in a large document?  Specifically, What are you doing
> to count Excel rows (or CR delimited text files) in a similar scenario?
>

-- 
Kirk Brooks
San Francisco, CA
===

*The only thing necessary for the triumph of evil is for good men to do
nothing.*

*- Edmund Burke*
**
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
**

Re: Counting occurrences of specific characters In a document

2017-11-08 Thread rooftop99--- via 4D_Tech
Thank you Cannon,

Progress indicator is not the only reason we need to know number of rows in 
advance.  However, your suggestion for using parse position and file size for 
process bars is intriguing and new to me.  I will investigate.

Kirk

> On Nov 8, 2017, at 7:11 PM, Cannon Smith via 4D_Tech <4d_tech@lists.4d.com> 
> wrote:
> 
> If the only reason you need to know the number of rows beforehand is to help 
> in showing a progress indicator, you could use the file size and current 
> parse position instead
> 
> --
> Cannon Smith
> 
>> On Nov 8, 2017, at 6:42 PM, rooftop99--- via 4D_Tech <4d_tech@lists.4d.com> 
>> wrote:
>> 
>> We are working with large Excel documents which contain upwards of 750K rows 
>> and we need to import each row into a 4D application to create records.  In 
>> advance of the import process I would like to know how may rows to expect.
> 
> **
> 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
**

Re: Counting occurrences of specific characters In a document

2017-11-08 Thread Cannon Smith via 4D_Tech
If the only reason you need to know the number of rows beforehand is to help in 
showing a progress indicator, you could use the file size and current parse 
position instead

--
Cannon Smith

> On Nov 8, 2017, at 6:42 PM, rooftop99--- via 4D_Tech <4d_tech@lists.4d.com> 
> wrote:
> 
> We are working with large Excel documents which contain upwards of 750K rows 
> and we need to import each row into a 4D application to create records.  In 
> advance of the import process I would like to know how may rows to expect.

**
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
**

Counting occurrences of specific characters In a document

2017-11-08 Thread rooftop99--- via 4D_Tech
Hi All,

The need:  
To know how many rows are in an Excel or Text file.

Overview:  
We are working with large Excel documents which contain upwards of 750K rows 
and we need to import each row into a 4D application to create records.  In 
advance of the import process I would like to know how may rows to expect.  
Currently we have a process that opens the document, loads the text, loops 
through with the Position command and counts Carriage Returns (delimiter) and 
returns the number. This is slow and a waste of resources…

Questions:  
What is the most efficient way to count the number of occurrences of a specific 
character in a large document?  Specifically, What are you doing to count Excel 
rows (or CR delimited text files) in a similar scenario?

Thanks!
Kirk
**
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
**