Jump to content

Recommended Posts

Hi,

is there an option for richedit to display @LF same way as @CRLF ?

This is needed for displaying linux files for servers to make them readable.

in notepad++ it's working this way in notepad not.

it's not for changing @LF to @CRLF.

the format should be kept for saving.

thanks for assistance.

cheers mike

Link to post
Share on other sites
Posted (edited)

Did you try replacing all @LF, that don't have a preceding @CR, with @CRLF?  That's what the StringAddCR() does.  Well, I don't know if it replaces the @LF with @CRLF  or inserts the @CR before the @LF.  But the end result is the same.  :)

Edit:

I just did a quick test.  Actually, StringAddCR() isn't quite that smart.  It will add a @CR before every @LF, regardless of whether it had a preceding @CR or not.  Therefore, I would use a regex to do the find/replace -- only replacing solo @LF's with @CRLF.  If you know that your text files will not have any @CRLFs, then StringAddCR() works fine.  Not sure why a file would have mixed line endings, but if it's possible, the regex find/replace would clean them up for display in a RichEdit control.

 

$sText = "This is a test." & @LF & @CRLF

ConsoleWrite("Before              = " & StringToBinary($sText) & @CRLF)
ConsoleWrite("After (StringAddCR) = " & StringToBinary(StringAddCR($sText)) & @CRLF)
ConsoleWrite("After (regex)       = " & StringToBinary(_StringLFtoCRLF($sText)) & @CRLF)

Func _StringLFtoCRLF($sText)
    Return StringRegExpReplace($sText, "(?<!\x0D)\x0A", @CRLF)
EndFunc

Console output:

Before              = 0x54686973206973206120746573742E0A0D0A
After (StringAddCR) = 0x54686973206973206120746573742E0D0A0D0D0A
After (regex)       = 0x54686973206973206120746573742E0D0A0D0A

 

Edited by TheXman
Link to post
Share on other sites

hi xman,

thanks for your answer.

the problem is not replacing @LF with @CRLF,
but if I save the file after changings this cannot keep like this, this must be made undo.

so in fact: I must analize the file if it's UNIX or not, keep this info in a variable like $bLinux = True.
Replace @LF with @CRLF for reading the file, and when I want to save file, look if $bLinux is True.
In this case I must replace @CRLF with @LF and then save it.

I thought, there would be perhaps already exist an easier way in richedit.
remember it's just for displaying the file readable, not for modifying it.

Cheers mike

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...