Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Simple question regarding saving strings to files. Re:

From: jkinraid:clear at: 15-Aug-2000 13:58

[tbrownell--yahoo--com] wrote:
> Hello again. > > I was just trying to write/append a series of strings > to a .txt file and retain the format so that I get the > following... > > a: "string a" > b: "string b" > c: "string c" > > How do you save the above strings to string-text.txt > so that when I read the .txt file I get... > > "string a" "string b" "string c" > "string a1" "string b1" "string c1" > > so that I can do a... > > str: read string-text.txt > foreach [a b c][print [a b c]]
I'm not exactly sure what you're looking for, but you could use the 'load function.
>> strings: {"string a" "string b" "string c"}
== {"string a" "string b" "string c"}
>> load strings
== ["string a" "string b" "string c" ]
>> foreach [a b c] load strings [print [a b c]]
string a string b string c The next thing you have to do is decide on the format of the file. There are various ways you could do it, here is one - a: "string a" b: "string b" c: "string c" write/append %string-text.txt remold [a b c] write/append %string-text.txt remold ["first" "second" "third"] write/append %string-text.txt remold ["baz" "boo" "foobar"] Now look at the file
>> read %string-text.txt
== {["string a" "string b" "string c"]["first" "second" "third"]["baz" boo "foobar"]} It is seperated into blocks of three strings, which is very easy to use. The 'load function will do all the conversion for you. You can also use the 'save function instead of write/append, which is basically the reverse of 'load.
>> foreach group load %string-text.txt [foreach [a b c] group [print [a b c]]]
string a string b string c first second third baz boo foobar Something that you should note is that Rebol seems to have some trouble with some strings that have speech marks and curly brackets in them. Julian Kinraid