Une bévue wrote:

> Paul Lutus <nospam / nosite.zzz> wrote:
> 
>> Sure. For mixed Windows and Unix/Linux line endings, just delete the
>> carriage returns:
>> 
>> data.gsub!{/\r/,"")
>> 
>> > 
> <snip />
>> Try this instead:
>> 
>> data = File.read(filename)
>> 
>> data.gsub!(/\r/,"")
>> 
>> array = []
>> 
>> data.split("\n").each do |line|
>>   # process lines here
>>   array << line
>> end
>> 
>> By using this approach, all your XML lines will be made uniform. At the
>> end of the processing, you will need to reintegrate the lines into a
>> block for storage:
>> 
>> data = array.join("\n")
>> 
>> file.open(filename,"w") { |f| f.write data }
> 
> OK fine thanks very much it's a nice solution somehow "normalizing" win*
> line endings  ;-)
> 
> 
> In fact i've a little bit modified what u've wroten :
> data.gsub!(/\r\n/,"\n")
> data.gsub!(/\r/,"\n")

What's the point? You have the following possibilities:

\r\n

\n\r

\n

All of these cases are handled by my posted method.

> 
> because i've discovered in the mean time i could have :
> \r
> \n
> \r\n
> 
> lines endings )))

Okay, the first ("\r") might be old-style Macintosh line endings. Here is a
solution for all the possibilities:

data.gsub!(%r{(\r\n|\n\r|\r)},"\n")

> 
> does \n\r exists ? (wikipedia says NO)

Doesn't matter. Someone might type it in manually. If it exists, the above
method will handle it.

> 
> also because the most part of the audio input file is "binary" datas
> there line ending is out of meaning, i suppose.

What? You are reading binary files? Then don't try to filter line endings.

If the file is text, you can filter line endings. Use the above method.

If the file is not text, do not filter anything.

-- 
Paul Lutus
http://www.arachnoid.com