[Gambas-user] Question on preserving Windows EOL

Willy@...3475... willy at ...3474...
Sun May 17 21:20:15 CEST 2015


On zo, 2015-05-17 at 19:39 +0200, Benoît Minisini wrote:
> >>
> >> 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)
> 


Okay, your suggestion worked well.
I wrote a little routine that gets executed before saving and checks a
setting to see if users want the EOL to be preserved in original format.

Private Sub PreserveEOL()
   
  Dim sTemp As String
  If Settings["Preferred/PreserveEOL"] = -1 Then
     sTemp = editMain.Text
     Select $sEOL
        Case "CR"             '\r      Old Apple Mac
           sTemp = Replace(sTemp, "\r\n", "\r")
           sTemp = Replace(sTemp, "\n", "\r")
        Case "CRLF"           '\r\n    Windows
           sTemp = Replace(sTemp, "\r\n", "\n")
           sTemp = Replace(sTemp, "\r", "\n")
           sTemp = Replace(sTemp, "\n", "\r\n")
        Case "LF"             '\n      Unix/Linux
           sTemp = Replace(sTemp, "\r\n", "\n")
           sTemp = Replace(sTemp, "\r", "\n")
     End Select
     editMain.Text = sTemp
  Endif
   
End

It works very well and so simple I could have thought about it.

Thanks

-- 
Kind regards,

Willy (aka gbWilly)

http://gambasshowcase.org/
http://howtogambas.org
http://gambos.org








More information about the User mailing list