Dan Zwell
4/30/2007 7:14:00 PM
Mike Steiner wrote:
> Okay, here's the birds-eye view:
>
> I'm converting some database data from pure text to CSV format, and I need
> to replace the newlines with something else (a space or a slash).
>
> Sample input record:
>
> Field1=value1
> Field2=value2
> more stuff in Field2
> ---------- # end-of-record separator
>
> Sample output record:
>
> FIELD1,FIELD2
> value1,value2 / more stuff in Field2
>
>
> Does that help?
>
> And the /m option only changes how "." is treated in a regexp, right?
>
> Can I use somestring.gsub ( /$/ , " " ) instead of somestring.gsub ( /\n/ ,
> " " )?
>
I guess you're right that /m isn't useful here. But gsub(/\n/, " ") does
seem to do what you want. And you can't use /$/ here because when you
try to substitute for $, it doesn't actually replace the end of the
line, but adds to it (so what you wrote adds a space to the end of each
line).
Dan