# How to find the number of identical cells in an array?

## Recommended Posts

There are 3 data files. I want to calculate how much quantity each type of cell. For example: hare == 2, wolf==2,bear==5.

1.txt

hare
hare
wolf

2.txt

wolf
bear
bear

3.txt

bear
bear
bear

```#include <Array.au3>

Local \$aArray[4][4]
Local \$iRows = UBound(\$aArray, 1)
Local \$iCols = UBound(\$aArray, 2)
Local \$iDimension = UBound(\$aArray, 0)

For \$i = 0 To \$iRows - 1
For \$j = 0 To \$iCols - 1
\$t = FileReadLine(''&\$j&'.txt', \$i)
\$aArray[\$i][\$j] =  \$t
Next
Next

_ArrayDisplay(\$aArray, 'table')```

##### Share on other sites

`_ArrayFindAll`

should help

Spoiler

Things I've Made: Transparency Machine
Misc Code Snippets:
Projects: SubnetCalc
Cool Stuff:

##### Share on other sites

```Local \$aResult = _ArrayFindAll(\$aArray, "bear")
_ArrayDisplay(\$aResult, "Found")
MsgBox(\$MB_SYSTEMMODAL, "Found", "Column" & \$aResult)```

doesn't show anything

```For \$i = 0 To \$iRows - 1
For \$j = 0 To \$iCols - 1
\$t= \$aArray[\$i][\$j]
If \$t=='bear' Then FileWrite('10.txt', '1')
Next
Next
\$rt=StringLen(\$r)
MsgBox(\$MB_SYSTEMMODAL,'bear', \$rt)```

So it sums up if there is a cell value.

Edited by Rei10
##### Share on other sites

Something like this :

```#include <Array.au3>

Const \$NUMBER_OF_FILES = 3
Local \$aArray[0]
For \$i = 1 to \$NUMBER_OF_FILES
_ArrayAdd (\$aArray, FileRead (\$i & ".txt"), 0, @CRLF)
Next
_ArraySort (\$aArray)
_ArrayDisplay (\$aArray)
Local \$aFinal [ubound(\$aArray)][2], \$sValue, \$iFinal = -1

For \$i = 0 to UBound(\$aArray)-1
If \$aArray[\$i] = "" Then ContinueLoop
If \$aArray[\$i] = \$sValue Then
\$aFinal[\$iFinal][1] += 1
Else
\$iFinal += 1
\$sValue = \$aArray[\$i]
\$aFinal[\$iFinal][0] = \$sValue
\$aFinal[\$iFinal][1] = 1
EndIf
Next

ReDim \$aFinal[\$iFinal+1][2]
_ArrayDisplay (\$aFinal)```

“They did not know it was impossible, so they did it” ― Mark Twain

Spoiler

Nine,thank you.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

• ### Recently Browsing   0 members

• No registered users viewing this page.
×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...