Jump to content

Recommended Posts

Posted (edited)

Convert EOL characters @CR and @LF to @CRLF. This is ideal if you have a document that has a mismatch of @CR and @LF line endings.

#include <MsgBoxConstants.au3>

; Convert all line endings to @CRLF.
Local $sString = StringEOLToCRLF('This is a sentence ' & @CR & Chr(12) & 'with ' & Chr(13) & 'whitespace.' & @CRLF) ; 12 = Form Feed, 13 = Carriage Return.

; Display the converted line endings.
MsgBox($MB_SYSTEMMODAL, '', $sString)

; Visually display that @CR and @LF have converted to @CRLF.
$sString = StringReplace($sString, @CRLF, '@CRLF')
MsgBox($MB_SYSTEMMODAL, '', $sString)

Func StringEOLToCRLF($sString) ; Initial Regular expression by Melba23 with a new suggestion by Ascend4nt and modified By guinness.
    Return StringRegExpReplace($sString, '(*BSR_ANYCRLF)\R', @CRLF) ; Idea by Ascend4nt
EndFunc   ;==>StringEOLToCRLF
Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Or simply:

StringRegExpReplace($sString, '\R', @CRLF)

 

See the Newline Sequences section of the PCRE Pattern specification.  It's a nice shortcut

My contributions:

  Reveal hidden contents

Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFsProcess CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen)Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery

Wrappers/Modifications of others' contributions:

_DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity)

UDF's added support/programming to:

_ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne)

(All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)

Posted (edited)

Ah, good to know. Thanks.

Wait, that includes f e.g.

Local $sString = StringEOLToCRLF("This is a sentence " & @CR & Chr(12) & "with " & Chr(13) & "whitespace." & @CRLF)
Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

True, its not just linefeed and carriage-returns..  I suppose for me it doesn't matter though, as they are all ending the current line.

My contributions:

  Reveal hidden contents

Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFsProcess CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen)Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery

Wrappers/Modifications of others' contributions:

_DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity)

UDF's added support/programming to:

_ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne)

(All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)

Posted
  On 7/21/2013 at 9:26 PM, Ascend4nt said:

True, its not just linefeed and carriage-returns..  I suppose for me it doesn't matter though, as they are all ending the current line.

Me neither. It's a good shortcut.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

FYI you can still restrict what R matches.

"(*BSR_ANYCRLF)R" is a pattern for matching only CR or LF or CRLF

On the contrary and by default with compiled options currently used:

"(*BSR_UNICODE)R" matches any Unicode newline sequence, i.e. is equivalent to "(?>rn|n|x0b|f|r|x85)"

BSR acronym stands for BackSlash R.

These two options only apply to what R matches and are independant of what PCRE regards as being a "line". "Line" breaks are themselves ruled by another set of options which govern what $ and ^ mean:

(*CR) carriage return

(*LF) linefeed

(*CRLF) carriage return, followed by linefeed

(*ANYCRLF) any of the three above

(*ANY) all Unicode newline sequences

All (*????) option must appear before all other options and in uppercase. Refer to PCRE docs for more details.

  Reveal hidden contents

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted

Ah! When I read BSR_ANYCRLF and such-like, I thought it had to be done a Jon's end. Go it jchd. Thanks.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

No its an old feature, already available long prior 3.3.8.1

  Reveal hidden contents

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

  • 10 months later...
Posted

Updated the function to using R.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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...