Jump to content

Recommended Posts

Posted (edited)

Hi all,

I need some help with StringRegExpReplace. I'm a bit of a noob with regular expressions. I want to replace all @CR characters in a string with @CRLF, but only if the carriage return isn't followed by a linefeed already.

Have been playing around with StringRegExpReplace, but can't get it to work. Any ideas?

Thanks

Edited by autoitter
Posted

you could first replace all @CR@LF with @CRLF and then replace all other remaining @CRs with @CRLF.

[right]~What can I say, I'm a Simplistic person[/right]

Posted (edited)

Hi all,

I need some help with StringRegExpReplace. I'm a bit of a noob with regular expressions. I want to replace all @CR characters in a string with @CRLF, but only if the carriage return isn't followed by a linefeed already.

Have been playing around with StringRegExpReplace, but can't get it to work. Any ideas?

Thanks

@toonboon I think what you meant was replace all @CRLF with @CR then replace all @CR with @CRLF.

@ autoitter, this might do what you want

;if text is $t then $r will be the converted text.
$r = StringRegExpReplace($t,"\r([^\n])","\r\n\1")
Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Posted

you could first replace all @CR@LF with @CRLF and then replace all other remaining @CRs with @CRLF.

@CR@LF is actually the same as @CRLF. My problem is that some @CR characters are followed by a @LF. I only want to replace "loose" @CR's.

I was trying something like this:

$strReceived = StringRegExpReplace($strReceived, "(\r)(^\n)", @CRLF & "\1")

But this doesn't work...

  • 9 years later...
Posted
stringreplace(StringReplace($text , @CR , @CRLF) , @LF & @LF , @LF)

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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