Jump to content

Changing Line Breaks to " & @CRLF & "


shanet
 Share

Recommended Posts

Hi all,

I just tried doing some research on changing the line breaks into " & @CRLF & " and tried what I found however it did not work! Below is the tiny experiment I am trying to get this working on before I implement it into my actual program.

Can anyone please tell me what is wrong here? Thanks.

#include <GUIConstantsEx.au3>

Opt("MustDeclareVars", 1)

Local $text, $msg, $txt

GUICreate("TEST", 400, 400)
$text = GUICtrlCreateEdit("Default Text", 30, 30, 350, 350)
GUISetState()

while 1
    $msg = GUIGetMsg()
    if $msg = $GUI_EVENT_CLOSE Then
        $txt = GUICtrlRead($text)
        StringReplace($txt, @CRLF, '" & @CRLF & "')
        MsgBox(0, "", $txt)
        ExitLoop
    EndIf
    
WEnd

shanet

[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:

%programfiles%/AutoIt3/autoit3.chm
Link to comment
Share on other sites

$txt = StringStripCR($txt)
$txt = StringReplace($txt, @LF, @CRLF)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

$txt = StringStripCR($txt)
$txt = StringReplace($txt, @LF, @CRLF)

GEOSoft,

Thankyou for your response, I tried it however it did not work. Are there any other options?

Thanks,

shanet

[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:

%programfiles%/AutoIt3/autoit3.chm
Link to comment
Share on other sites

Shanet, you forgot to assign the return value of StringReplace() to a variable.

Like this:

$txt=StringReplace($txt, @CRLF, '" & @CRLF & "')
Link to comment
Share on other sites

Shanet, you forgot to assign the return value of StringReplace() to a variable.

Like this:

$txt=StringReplace($txt, @CRLF, '" & @CRLF & "')

SORRY GUYS!!!

Thanks Ascend4nt for pointing that out.

My code is now as follows:

#include <GUIConstantsEx.au3>

Opt("MustDeclareVars", 1)

Local $text, $msg, $txt

GUICreate("TEST", 400, 400)
$text = GUICtrlCreateEdit("Default Text", 30, 30, 350, 350)
GUISetState()

while 1
    $msg = GUIGetMsg()
    if $msg = $GUI_EVENT_CLOSE Then
        $txt = GUICtrlRead($text)
        $txt = StringReplace($txt, @CRLF, '" & @CRLF & "')
        FileWrite("log.log", $txt)
        ExitLoop
    EndIf
    
WEnd

It works perfectly.

Thanks!

shanet

[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:

%programfiles%/AutoIt3/autoit3.chm
Link to comment
Share on other sites

More importantly, did you try it?

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Ignore. I added this post in error while playing with someone's iPad (seems close to impossible to edit a post with an iPad) then tried to delete it using firefox on a real PC but can't so I'll try ie in a minute.

So please don't reply for a few seconds and give me a chance to clean this up

can't delet this post in IE either so just ignore it.

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.
Link to comment
Share on other sites

Oops, sorry I didn't mean to offend I was just wondering (being he had everything set up to test this) What I meant was:

$txt = StringRegExpReplace($txt, '\r?\n', '" & @CRLF & "')

You didn't offend and I knew you meant to use an SRE there. I also knew what you posted wouldn't work. Actually an easier Expression there would be

$txt = StringRegExpReplace($txt, '\v{1,2}', '" & @CRLF & "')

I also don't think it's exactly what he wants because your replace string would give him the literal of

" & @CRLF & "

Now he may be looking for '"' & @CRLF & '"' or he may be looking for just the @CRLF with no double-quotes at all. It all depends on how accuratly he conveyed what he wants to do.

If He's just trying to make sure that all of the EOLs are @CRLF and not @CR or @LF Then it would probably be

$txt = StringRegExpReplace($txt, '\v{1,2}', @CRLF)

He can play with the results using the PCRE Toolkit in my signature.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Just making sure one other option/function is not overlooked.

StringAddCR ( "string" )

Takes a string and prefixes all linefeed characters ( Chr(10) ) with a carriage return character ( Chr(13) ).

If StringInString($sText, @LF) Then $sText = StringStripCR($sText)
$sText = StringAddCR($sText)
- not fit for text with mixed linefeed. (use RE)

- not fit for UTF strings. (if I'm correct)

- single RE probably faster. (assumption)

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Just making sure one other option/function is not overlooked.

If StringInString($sText, @LF) Then $sText = StringStripCR($sText)
$sText = StringAddCR($sText)
- not fit for Text with mixed linefeed use. (use RE)

- not fit for UTF strings. (if I'm correct)

- single RE probably faster. (assumption)

The RE is probably faster. I'm pointing out that there are many ways to skin the cat here and you have just added another. I'm still mot clear on what the OP really wants. Doues he just want to replace the EOL character or does he want to replace it with a litteral (which makes no sense but it's not my script)?

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Did someone miss the point in the thread where shanet said 'It works perfectly', in response to my post? No need for alternative code or ideas. One StringReplace() did what was necessary.

Also, this pondering of 'what the original poster really wanted' is ridiculous. He got what he needed. You can continue to deliberate why someone would replace @CRLF with '" & @CRLF &"', but what does it matter, he got his answer. (and for what its worth, it looks like he's generating AutoIt code from text entered into an input box)

Link to comment
Share on other sites

Good points and you're correct, I did miss that reply. Oh well, life will go on.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I'm still mot clear on what the OP really wants. Doues he just want to replace the EOL character or does he want to replace it with a litteral (which makes no sense but it's not my script)?

What I am doing is asking for input where they may input line breaks, and saving it to a file where it is to remain on one line only. The reason I include "s is easier to show you why rather than explain (see end of post).

Did someone miss the point in the thread where shanet said 'It works perfectly', in response to my post? No need for alternative code or ideas. One StringReplace() did what was necessary.

I think they did, however I have read over their posts and there are a few good posts. I dont really mind as long as it doesnt spark any bad feelings in the forums, as an answer could be posted that is able to help further.

Also, this pondering of 'what the original poster really wanted' is ridiculous. He got what he needed. You can continue to deliberate why someone would replace @CRLF with '" & @CRLF &"', but what does it matter, he got his answer. (and for what its worth, it looks like he's generating AutoIt code from text entered into an input box)

:shifty:

Good points and you're correct, I did miss that reply. Oh well, life will go on.

No hard feelings :P

So what the file will contain is basically this:

[start of file]

Date given by user|Time event takes place on given day|Name of event|Description of event|priority

Date given by user|Time event takes place on given day|Name of event|Description of event|priority

Date given by user|Time event takes place on given day|Name of event|Description of event|priority

EndofFile

As you can see, there are multiple lines here, a single line represents a single event. The [start of file] just represents the start of the file for here in the forum however the EndofFile will be found in the actual file.

Again, every line is a new event, that is why I wanted to change line breaks into " & @CRLF & ". The | symbolizes the next part of the event, therefore assigned to a new variable.

They will be assigned to an array somewhat like;

$line1[1] = Date

$line1[2] = Time

$line1[3] = Name

...

$line2[1] = Date

and so on. That is not actual code, rather the assignment of the event properties to the variables.

The line that is targeted with " & @CRLF & " is the description line, the only place where they are able to insert a line break, however it is targeted at input (obviously).

However, although the writing worked beautifully, however the reading did not?

I am just running tiny scripts dedicated to this instead of implementing it at the moment, the codes are below:

Read from log.log

Local $txt
$txt = FileReadLine("log.log", 1)

MsgBox(0, "", $txt)

Write to log.log

#include <GUIConstantsEx.au3>

Opt("MustDeclareVars", 1)

Local $text, $msg, $txt

GUICreate("TEST", 400, 400)
$text = GUICtrlCreateEdit("Default Text", 30, 30, 350, 350)
GUISetState()

while 1
    $msg = GUIGetMsg()
    if $msg = $GUI_EVENT_CLOSE Then
        $txt = GUICtrlRead($text)
        $txt = StringReplace($txt, @CRLF, '" & @CRLF & "')
        FileWrite("log.log", $txt)
        ExitLoop
    EndIf
    
WEnd

log.log contents

Default Text" & @CRLF & "Test

Where it is " & @CRLF & " in the log file, I have tried:

@CR

@LF

@CRLF

" @CRLF "

& @CRLF &

however none of them have inserted line breaks when read.

Does anyone have a solution to this problem??

Thanks all (again). It seems that it was not all finished like I thought it was? And sorry for the elephant sized post :x

shanet

[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:

%programfiles%/AutoIt3/autoit3.chm
Link to comment
Share on other sites

Like to suggest that you also could use a other ASCII control code for marking a in-line/data linefeed.

It would remove any potential misconception about that in-line/data marker. (for both humans, editors and code wize of course.)

(A other alternative is of course using something general like '\r\n'. But if its just something for personal/limited-internal use thats not really needed. But you do know directly what they mean if you look at them again in 5 years from now. :x )

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Like to suggest that you also could use a other ASCII control code for marking a in-line/data linefeed.

It would remove any potential misconception about that in-line/data marker. (for both humans, editors and code wize of course.)

(A other alternative is of course using something general like '\r\n'. But if its just something for personal/limited-internal use thats not really needed. But you do know directly what they mean if you look at them again in 5 years from now. :shifty: )

\r\n doesnt work for me :x

I tried this:

Msgbox(0,"","This is a" & \r\n & "new line")

and this:

Msgbox(0,"","This is a\r\nnew line")

They dont work :P I must be implementing them wrong?

[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:

%programfiles%/AutoIt3/autoit3.chm
Link to comment
Share on other sites

They dont work :x I must be implementing them wrong?

Thats because its not something thats natively supported by Autoit itself (not really needed). As such its something that needs to be coded into your script as a feature.

"But if its just something for personal/limited-internal use thats not really needed."

- - -

A little background information. Bit technical though.

http://en.wikipedia.org/wiki/Newline#In_programming_languages

- - -

[below]

AutoIt won't recognize \r\n except in a Regular Expression.

+ Pattern part in StringFormat() Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

AutoIt won't recognize \r\n except in a Regular Expression.

In AutoIt \r\n translates to @CR & @LF which of course is @CRLF.

Using the code Ascend4nt posted, have you tried this to get what you want

$txt=StringReplace($txt, @CRLF, '" & @CRLF & "' & @CRLF)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

AutoIt won't recognize \r\n except in a Regular Expression.

In AutoIt \r\n translates to @CR & @LF which of course is @CRLF.

Using the code Ascend4nt posted, have you tried this to get what you want

$txt=StringReplace($txt, @CRLF, '" & @CRLF & "'[b] & @CRLF[/b])

The problem with the code Ascend4nt posted is it writes to more than one line, which as I said above is not how I want it done, thats the reason behind this thread is to keep it on one line.

[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:

%programfiles%/AutoIt3/autoit3.chm
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...