[Gambas-user] Question on preserving Windows EOL

Benoît Minisini gambas at ...1...
Sun May 17 19:39:36 CEST 2015


Le 17/05/2015 19:21, T Lee Davidson a écrit :
> On 05/17/2015 10:18 AM, Willy at ...3475... wrote:
>> Hi All,
>>
>> I've been struggling with something I would like to implement.
>>
>> A user asked me if it would be possible to preserve Windows EOL (CRLF)
>> for files originating from Windows, but opened and modified in gbEdit
>> (Gambas written texteditor).
>>
>> What happens now is that, if I add a few new lines to a windows
>> originated text file, the new lines will be saved with a linux EOL (LF).
>> The lines already having the Windows EOL (CRLF) are preserved.
>>
>> gbEdit makes use of a Editor control. Saving the contents is now done
>> with a simple:
>>
>> File.Save($sPathFileLoaded, editMain.Text)
>>
>> Where $sPathFileLoaded is the full path and name of the file
>> AND
>> editMain.Text is the name of the Editor control holding the content.
>>
>> Upon opening a file gbEdit determines the EOL and returns either:
>> CRLF for Windows EOL
>> LF for Unix EOL
>> CR for Classic Apple Mac EOL
>>
>> So I have all in place to determine when Windows EOL needs to be used
>> upon saving.
>>
>> What I need is that new lines added, to a file already using Windows
>> EOL, have to be saved with Windows EOL as well.
>>
>> I imagine I could save the file as a stream, making sure the proper EOL
>> is added, but was wondering if there might be any easier way in Gambas
>> that can do the job (as somehow that often turns out to be the case).
>>
>> Any suggestions?
>>
>>
>

Something quick and dirty like that?

' EolText = "\n" ' Unix
EolText = "\r\n" ' Windows
' EolText = "\r" ' Mac

Text = Replace(Text, "\r\n", "\n")
Text = Replace(Text, "\r", "\n")
if EolText <> "\n" Then Text = Replace(Text, "\n", EolText)

-- 
Benoît Minisini




More information about the User mailing list