Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Clipper > Re: Text to arr...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 9 Topic 3850 of 3903
Post > Topic >>

Re: Text to array

by sebas22 <nospam@[EMAIL PROTECTED] > Feb 25, 2008 at 10:36 PM

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




 9 Posts in Topic:
Text to array
"Derek" <dal  2008-02-25 23:43:09 
Re: Text to array
"E. Fridman" &l  2008-02-25 08:25:19 
Re: Text to array
otto <ohaldi@[EMAIL PR  2008-02-25 21:18:49 
Re: Text to array
sebas22 <nospam@[EMAIL  2008-02-25 22:36:32 
Re: Text to array
"Derek Yim" <  2008-02-26 10:25:35 
Re: Text to array
"Stephen Quinn"  2008-02-26 03:10:38 
Re: Text to array
"tom knauf" <  2008-02-26 16:46:59 
Re: Text to array
Ray Marron <google@[EM  2008-02-26 06:38:44 
Re: Text to array
dlzc <dlzc1@[EMAIL PRO  2008-02-26 11:00:55 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 0:01:16 CDT 2008.