On Thu, 2013-02-21 at 01:50 +0100, Charles Goyard wrote:
IOhannes m zmoelnig wrote:
you can tell [textfile] to use CR/LF/CRLF as line delimiters by opening the file in "cr" mode, like [open file.txt cr(
then you will need to stop through the lines by [bang(ing [textfile] till the end is reached. if you want to read the entire file at once, use [until] (with the 2nd outlet of [textfile] fed back to the 2nd inlet of [until], so it stops banging once the textfile is done. convert each line with [any2bytes], use [list append] to append '10' (the newline), and append those lists using another [list append].
Ok here's my take to this. I was unable to make it work with only two list append, so I used 1 append and 2 prepend. There sure is a more logical way to that. But at least it works :).
Please correct my patch and help me learn !
Thanks a lot for your help.
Your patch breaks when you have a line with a comma in your text file. Such a line is broken into two lines.
Regarding your insistence to do that task with Pd, I think you should reconsider your reasoning. Pd is not particular strong in string processing, exactly because of reasons like this. IMHO, your best bet is to not use character representation at all in Pd which is probably the only safe way not to get in conflict with special characters in Pd (at least as long as there isn't a proper way to escape them).
See attached example with [mrpeach/binfile] -> [text3d].
This example doesn't do any processing at all, it only passes the data "untouched" to [text3d]. If you really want to do some processing, I'd probably do that outside of Pd. There are plenty of ways to roll your own external class with any of several scripting languages (bash, lua, python, tcl, etc.). I'd probably offload all the real string processing to such an external.
Roman