On Mon, 25 Feb 2008 23:43:09 +0800, "Derek" <dalikyim@[EMAIL PROTECTED]
>
wrote:
>Hi,
>How can I read the text file into an array.
>Please advise.
*------------------------------- StrToArr --------------------------*
* Transform a string into an array, dependiing on the
* separator cSep
* Ex : StrToArr("12/34", "/") -> {"12", "34"}
* StrToArr("12/34", "$") -> {"12/34"}
* StrToArr("", "$") -> {}
* StrToArr(c, "") -> {c}
* If lKeepNul is .t., we keep empty lines ( == "").if .f., we forget
them (default : .f.)
function StrToArr(cStr, cSep, lKeepNul)
local aArr := {}, cLeft
local nPos
if ! ischar(cSep) .or. cSep == ""
return {cStr}
endif
if ! empty( lKeepNul ) // Si on veut garder les lignes vides
("")
do while cSep + cSep $ cStr
cStr := strtran( cStr, cSep + cSep, cSep + " " + cSep )
enddo
endif
nPos := at(cSep, cStr)
do while nPos > 0
cLeft := substr(cStr, 1, nPos - 1)
if len(cLeft) > 0
aadd( aArr, trim(cLeft) )
endif
cStr := substr(cStr, nPos + 1)
nPos := at(cSep, cStr)
enddo
if .not. empty(cStr)
aadd(aArr, cStr)
endif
return aArr
*---- EoP StrToArr ----*
--
Regards,
Sebas


|