Conditional delete

Discussion, questions and support.
david
Posts: 21
Joined: Jun 1st, ’17, 20:08

Post by david » Jun 27th, ’18, 19:37

Seems somehow that Sigil (the editor) is not the problem.

For example, I executed your script in Sigil and here is the result: http://share.epiclemon.com/sZdj
I did the same thing in a simple notepad and the same result: http://share.epiclemon.com/sZfw
Here is what I really need: http://share.epiclemon.com/sZZD

I'll keep trying, but if you can help me it would be really awesome. I've sent a small sample text to your support email.

Thank you so much!
david
Posts: 21
Joined: Jun 1st, ’17, 20:08

Post by david » Jun 27th, ’18, 21:57

Seems I could make some progress :) Here is what I have now:

StringReplace, Clipboard, Clipboard, `r`n`r`n, %A_Space%, All

This works fine, the only problem is that it takes from the clipboard so I have to modify it to suit my needs. So, I go back to the original code and modify, which is:

Code: Select all

send {End}{Space}
send +{Right} ;select character on the right
send ^c ;copy it to clipboard
if (clipboard=" " or clipboard="`r`n`r`n")
	send {Del}
sleep 150
But then, it does the same. I am wondering if the clipboard="`r`n`r`n" is correct way of checking agains this special characters. If I do clipboard=`r`n`r`n (without quotes) it does not seem to work fine. Any ideas around this? Thanks so much!
User avatar
Marko
Posts: 1728
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Jun 28th, ’18, 07:45

Only small change is required if you want to remove new lines:

Code: Select all

send ^c
sleep 100
text:=Clipboard

newtext:=""
Loop, parse, text, `n,`r
{
	line:=A_LoopField
	line=%line%
	If (line<>"")
		newText.=line " "  ;added space instead of a new line
}

clipboard:=newtext
sleep 100
send ^v
You can also change the file. This assumes the sampletext.txt file is in the script's folder:

Code: Select all

FileRead, text, sampletext.txt

newtext:=""
Loop, parse, text, `n,`r
{
	line:=A_LoopField
	line=%line%
	If (line<>"")
		newText.=line " "
}

FileDelete, sampletext_mod.txt
FileAppend, %newtext%, sampletext_mod.txt
david
Posts: 21
Joined: Jun 1st, ’17, 20:08

Post by david » Jun 28th, ’18, 17:20

wow, you are the man Marko! Thanks so much for your help! ;)
david
Posts: 21
Joined: Jun 1st, ’17, 20:08

Post by david » Jun 28th, ’18, 21:52

Sorry to ask for another thing. I found out that using this takes out italics, underline, etc that I have previously on the text that is being manipulated.

So, back to square one. The script you created is awesome and works great, but unfortunately I need a more manual solution, which is for now, to delete the newline only if the next character is actually a newline and not a regular character. Is there a way to do it in this script you shared before?

Code: Select all

send {End}{Space}
send +{Right} ;select character on the right
send ^c ;copy it to clipboard
MsgBox % InStr("clipboard","`r`n`r`n")
if (clipboard=" " or clipboard="`r`n`r`n")
	send {Del}
sleep 150
User avatar
Marko
Posts: 1728
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Jun 29th, ’18, 15:21

Not sure, how about this?

Code: Select all

send {End}{Space}
send +{Right}+{Right} ;select two
send ^c
if (clipboard="`r`n`r`n")
	send {Del}{Del}
Instead of end of the line {End} you could go to the end of paragraph: +^{Down}{Right}{Left}
david
Posts: 21
Joined: Jun 1st, ’17, 20:08

Post by david » Jul 1st, ’18, 18:02

Thanks for the help!

In here, more than selecting two characters or anything like that, seems that the check condition if the copied character is a new line is not being triggered correctly :(
User avatar
Tom
Posts: 796
Joined: Nov 24th, ’15, 23:39

Post by Tom » Jul 2nd, ’18, 11:42

Each editor is different. I tried in Sigil and this appears to work for me:

Code: Select all

send {End}{Space}
send +{Right}+{Right}
send ^c
if (clipboard="`r`n`r`n`r`n")
	send {Del}
Even better, why don't you edit the html format? Click on <> icon and then use Find/Replace - copy unwanted tags from the text to Find field and replace all with a space.
david
Posts: 21
Joined: Jun 1st, ’17, 20:08

Post by david » Jul 3rd, ’18, 00:54

I saw that Sigil has some bugs. I have seen that whenever I delete a non-newline character, whenever I paste it to notepad, it is pasted without any newline character at all. So, maybe this is why it is not working fine. Anyways, unfortunately I am stuck with this editor.

Also, I tried what you suggested about editing the HTML, and whenever I do that it kind of breaks the formatting of the justification. It is weird, but anyways.

Marko, thanks a lot for all your help. I've taken already too much of your time. Thanks sooo much for your help and for building such a wonderful software :D
Post Reply