;Script Options
;$SO=SETOPTION("Explicit", "ON")
;$SO=SETOPTION("NoMacrosInStrings", "ON")
;$SO=SETOPTION("NoVarsInStrings", "ON")
BREAK ON
CLS
$file = "C:\temp\file.txt"
$handle = FreeFileHandle()
$sitearray = loadfile($file,"@crlf")
For Each $line In $sitearray
; $line
$field = Split($line," ")
$field[0] ?
If InSTR($field[0],"K")
$field[0]
Else
"No K in string" ?
EndIf
Next
;Functionction LoadFile()
;
;Author Bryce Lindsay Bryce@isorg.net
;
;Action Loads a file in to a variable or an array.
;
;Syntax LoadFile("Filename",[Array Delim], [UNI/ANSI file type])
;
;Version 1.1
;
;Date Revised 9:14 AM 8/15/2006
;
;Parameters Filename
; name of the file that you want to load.
;
; Optional Array
; set this option if you want to return the
; information as an array split on the given value
;
; Unicode/ANSI file type
; 3 = force file open as ANSI
; 2 = forse file open as UNI
; 1 = Opens the file using the system default. (the UDF will use this as default)
;
;Remarks finaly made this into a UDF and posted it... got tired
; of having to hunt it down.
;
;Returns if the array flag is not set it returns a variable
; containing the contents of the file.
;
; if the array flag is set, it will return an array
; of the file split on the value of the given variable
;
;Dependencies Scripting.FileSystemObject
;
;KiXtart Ver 4.51
;
;Example(s)
; ;load the file test.txt into a variable
; $Data=loadfile('test.txt')
; ? $data
;
; ;load the file "test.txt" into an array split on @crlf
; $data = loadfile('test.txt',@crlf)
; for each $line in $data
; ? $line
; next
;*/
Function loadfile($file, optional $array, $Uni)
DIM $fso,$f,$fs
if $uni $uni = $uni-3 else $uni = -2 endif
if not $uni $uni = -2 endif
$fso = CreateObject("Scripting.FileSystemObject")
$f = $fso.GetFile($file)
If @ERROR Exit 2 EndIf
$fs = $f.OpenAsTextStream(1,$uni)
if not $array
$loadfile = $fs.Read($f.size)
else
$loadfile = Split($fs.Read($f.size),$array)
endif
Exit @ERROR
EndFunction