Simple question regarding saving strings to files.
[1/3] from: tbrownell::yahoo::com at: 14-Aug-2000 17:47
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]]
Or is there a better way to do this?
Thanks again,
TBrownell
[2/3] from: bhandley:zip:au at: 15-Aug-2000 11:13
Howdy,
>> help save
USAGE:
SAVE where value /header header-data
DESCRIPTION:
Saves a value or a block to a file or url.
SAVE is a native value.
>> help mold
USAGE:
MOLD value
DESCRIPTION:
Converts a value to a REBOL-readable string.
MOLD is a native value.
>> help load
USAGE:
LOAD source /header /next /library /markup
DESCRIPTION:
Loads a file, URL, or string. Binds words to global context.
LOAD is a native value.
>> load {"stringa" "stringb" "stringc"}
== ["stringa" "stringb" "stringc"]
So you can do this....
>> save %your-file1.txt ["string a" "string b" "string c"]
>> print load %your-file1.txt
string a string b string c
Or this (which retains the containing block in the file)...
>> write %your-file2.txt mold ["string a" "string b" "string c"]
>> print load %your-file2.txt
string a string b string c
Brett.
[3/3] 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
<<quoted lines omitted: 10>>
> 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
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted