Getting text out of a field

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Andycal
Posts: 144
Joined: Mon Apr 10, 2006 3:04 pm

Getting text out of a field

Post by Andycal » Sat Feb 09, 2008 3:13 pm

I've got a text file that I've got the first line out of by using this:

Code: Select all

    put fld "TemplatePath" into sFile
    open file sFile for read
    read from file sFile at 1 until EOF
    put it into fld "fldContent"
    put the first line of fld "fldContent" into wTitle


How do I now get the rest of the file into another variable? I thought it might be as simple as:

Code: Select all

put line 2 to eof into fld "fldRest"
But it's not.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Post by Klaus » Sat Feb 09, 2008 3:45 pm

Hi Andy,

you can save some typing by using the "url" syntax:

Code: Select all

...
    put fld "TemplatePath" into sFile 
    put URL("file:" & sFile) into fld "fldContent" 
    
    ## Use "file:" for text files and "binfile:" for binary data

    put the line 1 of fld "fldContent" into wTitle
    put line 2 to -1 of fld "fldContent" into "fldRest"
   # Yes you can start counting from the end of fields/text :-)
   # line -1 = last line
   # line -2 = last but one line etc...
Best

Klaus

Andycal
Posts: 144
Joined: Mon Apr 10, 2006 3:04 pm

Post by Andycal » Sat Feb 09, 2008 4:15 pm

Brilliant, cheers!

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”