Creating CSV files
[1/5] from: learned:talentsinc at: 26-Sep-2001 11:47
I have a block, and am trying to write it out to a CSV type file, with each
element of the block a seperate value i.e.:
["a" "b" "c" "d"]
being written out as:
a,b,c,d
I'm missing something, seems like this should be a piece of cake. Anyone
want to bail me out?
Thanks
---
G. Edw. Learned - [learned--talentsinc--net]
(Never apply a Star Trek Solution to a Babylon Five Problem)
[2/5] from: m:koopmans2:chello:nl at: 26-Sep-2001 19:03
a: [ "a" "b" "c" "d"]
res: copy {}
foreach e a [ repend res [ e ","]]
;remove the lsat comma
remove skip tail res -1
--Maarten
[3/5] from: ryanc:iesco-dms at: 26-Sep-2001 10:10
Here is a function I wrote a looong time ago to export into different formats.
I can see about 25 ways to make it better now, but it at least shows you the
general idea.
--Ryan
delimit: Function
[
{Returns delimitation you specify in example.}
db [block!] "Block containing blocks of records, or just a single record
block."
example [string!] {String with x's (#"x") specifying where data goes.}
] [
rv
new-records
new-record
] [
if not block? db/1 [db: reduce [db] ]
new-records: copy ""
foreach record db [
new-record: copy example
parse new-record [
some [to "x" x: (
remove/part x 1
x: insert x first record
either not tail? next record [record: next record] [record: [""] ]
)
:x
]
]
append new-records head new-record
]
new-records
]
G. Edw. Learned
wrote:
> I have a block, and am trying to write it out to a CSV type file, with each
> element of the block a seperate value i.e.:
<<quoted lines omitted: 11>>
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
--
Ryan Cole
Programmer Analyst
www.iesco-dms.com
707-468-5400
[4/5] from: jelinem1:nationwide at: 26-Sep-2001 13:10
My solution would be:
>> rejoin/with ["a" "b" "c" "d"] ","
== "a,b,c,d"
A long time ago, I redefined 'rejoin:
rejoin: func [
"Reduces and joins a block of values - allows /with refinement."
block [block!] "Values to reduce and join"
/with
join-thing "Value to place in between each element"
][
block: reduce block
if with [
while [not tail? block: next block]
[insert block join-thing block: next block]
block: head block
]
append
either series? first block [copy first block]
[form first block]
next block
]
Since then I've read about issues (from this ML) about redefining /Core
words with regards to sharing code, but aside from that I see the ability
to redefine words as a strength. BTW the new definition is a modification
of the old, not a re-write.
- Michael
G. Edw. Learned
<[learned--talentsinc--net]>
Sent by: [rebol-bounce--rebol--com]
09/26/01 11:47 AM
Please respond to rebol-list
T
To: [rebol-list--rebol--com]
cc:
bcc:
Subject: [REBOL] Creating CSV files
I have a block, and am trying to write it out to a CSV type file, with
each
element of the block a seperate value i.e.:
["a" "b" "c" "d"]
being written out as:
a,b,c,d
I'm missing something, seems like this should be a piece of cake. Anyone
want to bail me out?
Thanks
---
G. Edw. Learned - [learned--talentsinc--net]
(Never apply a Star Trek Solution to a Babylon Five Problem)
[5/5] from: ammoncooke::yahoo::com at: 26-Sep-2001 13:35
Clever implementation! I definetly think that should be on the list of REPs
;D
Enjoy!!
Ammon
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted