Converting a headline

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Billykid
Posts: 95
Joined: 16 Sep 2019, 08:59

Converting a headline

Post by Billykid » 27 Oct 2021, 08:26

Look at my sentence in the example. There is a blank line above and below this sentence.
The sentence "This is my headline" does not contain a period.
I want to add a period to this sentence and remove the two blank lines.
How do I do that? Thank you very much for your help.
Before:

Code: Select all


This ist my headline

After:

Code: Select all

This ist my headline.

User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Converting a headline

Post by mikeyww » 27 Oct 2021, 09:22

Code: Select all

str =
(

This ist my headline

)
str := Trim(str, " `t`r`n") "."
MsgBox, 64, Result, %str%

Billykid
Posts: 95
Joined: 16 Sep 2019, 08:59

Re: Converting a headline

Post by Billykid » 28 Oct 2021, 10:06

@mikeyww
Thanks a lot. Yet I had something different in mind.
So let me give you another example what I'm looking for.

Code: Select all

FileRead , str, Headline.txt
Content of str:

Code: Select all

This line is above the headline and has a period.

This is my headline 

This line is below the headline and has a period.
After conversion I would like to get this result,
the str variable should contain this now:

Code: Select all

This line is above the headline and has a period.
This is my headline.
This line is below the headline and has a period.
The empty lines are gone and the headline ended
with a period.

How can I do this? Thanks for your help!

User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Converting a headline

Post by mikeyww » 28 Oct 2021, 10:10

It can be done as long as you can post a description of how you would like to define the end of a sentence.

Billykid
Posts: 95
Joined: 16 Sep 2019, 08:59

Re: Converting a headline

Post by Billykid » 28 Oct 2021, 10:21

The middle sentence (headline) initially has no punctuation mark at the end and is separated from the other two sentences by a blank line. After conversion, the blank lines should disappear and the middle sentence should have a punctuation mark at the end. I don't care if it's a period, question mark or exclamation mark.

User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Converting a headline

Post by mikeyww » 28 Oct 2021, 11:27

Code: Select all

str =
(
This line is above the headline and has a period.

This is my headline 

This line is below the headline and has a period.
)
MsgBox, 64, Headline, % str := headline(str)

headline(str) {
 Return RegExReplace(str, "\v+(.+?)\v+", "`n$1.`n")
}

Billykid
Posts: 95
Joined: 16 Sep 2019, 08:59

Re: Converting a headline

Post by Billykid » 28 Oct 2021, 12:03

Thank you so much Mike!!!

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Converting a headline

Post by flyingDman » 28 Oct 2021, 13:05

This puts a final period to any line that does not have one (not just the middle one) and deletes all blank lines (not just single blank lines). It also works if you have 2 or more "headlines":

Code: Select all

str =
(
This line is above the headline and has a period.

This is my headline


This is my second headline

This line is below the headline and has no period
)
msgbox % trim(RegExReplace(str "`n","(\.?\v+)",".`n"),"`n")
14.3 & 1.3.7

Post Reply

Return to “Ask for Help (v1)”