#include <file.au3>
#include <array.au3>
; #FUNCTION# ====================================================================================================================
; Name...........: _FileCountDefCharacters
; Description ...: Returns the number of defined characters.
; Syntax.........: _FileCountDefCharacters($file, $character)
; Parameters ....: $file - Path & Name of the File to Read.
;                  $character - Character or Characters you want to Count
; Return values .: Success - Returns the number of the defined characters
;                  Failure - Returns 0
; Author ........: FireFlyer <wolfijentner@web.de>
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; No
; ===============================================================================================================================
Func _FileCountDefCharacters($file, $character)
	Dim $array
	_FileReadToArray( $file, $array)
	$result = 0
For $i = 1 To $array[0]
	$start = 1
While 1
	$littlestring = StringMid($array[$i], $start)
	$stringsearch = StringInStr ( $littlestring, $character)
If $stringsearch <> 0 Then
	$result = $result + 1
	$start = $stringsearch + $start
Else
	ExitLoop
EndIf
WEnd
Next
Return $result
EndFunc

; #FUNCTION# ====================================================================================================================
; Name...........: _FileFindDefCharacters
; Description ...: Returns the Character/Position and Number of Results of defined characters.
; Syntax.........: _FileFindDefCharacters($file, $search[, $showcount][, $lineachar][, $text])
; Parameters ....: $file - Path & name of the file to read.
;                  $search - The word or characters to search.
;				   $showcount - 1 [The number of results will be shown at last] ; 0 (Default) [No number will be shown]
;				   $linechar - 1 [The position of the founded text will be shown] ; 0 (Default) [No position will be shown]
;				   $text - 1 [Additional text will be shown (Example: Line: 3)] ; 0 (Default) [No text will be shown (Example: 3)]
; Return values .: Success - Returns an Array with the $search and possible additional: Count; Position; Text
;                  Failure - Returns 0
; Author ........: FireFlyer <wolfijentner@web.de>
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; No
; ===============================================================================================================================
Func _FileFindDefCharacters($file, $search, $showcount = 0, $lineachar = 0, $text = 0)
	Dim $array2, $resarray
	$resarray = _ArrayCreate("Results:")
	$count = StringLen($search)
	_FileReadToArray( $file, $array2)
	$result = 0
For $i = 1 To $array2[0]
	$start = 1
While 1
	$littlestring = StringMid($array2[$i], $start)
	$stringsearch = StringInStr ( $littlestring, $search)
If $stringsearch <> 0 Then
	If $lineachar = 1 Then
		If $text = 1 Then
			_ArrayAdd( $resarray, $search)
			_ArrayAdd( $resarray, "Line: "&$i)
			_ArrayAdd( $resarray, "From: "&$stringsearch&" To: "&$stringsearch + $count)
		Else
			_ArrayAdd( $resarray, $search)
			_ArrayAdd( $resarray, $i)
			_ArrayAdd( $resarray, $stringsearch&";"&$stringsearch + $count)
		Endif
	Else
		_ArrayAdd( $resarray, $search)
	EndIf
	$start = $stringsearch + $start + $count
	$result = $result + 1
Else
	ExitLoop
EndIf
WEnd
Next
If $showcount = 1 Then
	If $text = 1 Then
		_ArrayAdd( $resarray, "Objects found: "&$result)
	Else
		_ArrayAdd( $resarray, $result)
	EndIf
EndIf
Return ($resarray)
EndFunc