How to display two lines from one lines. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
hancre
Posts: 251
Joined: 02 Jul 2021, 20:51

How to display two lines from one lines.

Post by hancre » 17 Feb 2023, 00:53

I hope that
1. the two sentences in a line be splited to each sentence in a line.
2. remove the white space in left area.

This following script works well at first part. But it has two problems.
1. doesn't remove the white space in each left area.
2. doesn't split for the last parts like the example.

How can I fix it? Thanks for any help in advance.

Code: Select all

!r::
   Clipboard := "" 
   Send, ^c
   str:= Trim(Clipboard)
   Clipboard:=RegExReplace(str, "([\p{L}\p{N} ,-]+[\p{P}])\s*([\p{L}\p{N} .。、;!?]+[\p{P}]\S*)", "${1}`n${2}")
   Send ^v
Return 

( raw data)
Nice to meet you. I'm Steve.
We had watched that movie before, so we knew the ending. 우리는 전에 그 영화를 보았으므로 결말을 알았습니다.

They had cleaned the house before their guests arrived. 그들은 손님이 도착하기 전에 집을 청소했습니다.

He had spoken to the manager about the issue earlier. 그는 이전 에이 문제에 대해 관리자에게 이야기했습니다.

They had played that game before, so they knew the rules 그들은 전에 그 게임을했기 때문에 규칙을 알았습니다.

By the end of the week, I will have completed this project. 주가 끝날 무렵, 나는이 프로젝트를 완료 할 것입니다.

She will have graduated from college by this time next year. 그녀는 내년 에이 시간까지 대학을 졸업했을 것입니다.

( result )
Nice to meet you.
I'm Steve.
We had watched that movie before, so we knew the ending.
우리는 전에 그 영화를 보았으므로 결말을 알았습니다.

They had cleaned the house before their guests arrived.
그들은 손님이 도착하기 전에 집을 청소했습니다.

He had spoken to the manager about the issue earlier.
그는 이전 에이 문제에 대해 관리자에게 이야기했습니다.

They had played that game before, so they knew the rules 그들은 전에 그 게임을했기 때문에 규칙을 알았습니다.
By the end of the week, I will have completed this project. 주가 끝날 무렵, 나는이 프로젝트를 완료 할 것입니다.
She will have graduated from college by this time next year. 그녀는 내년 에이 시간까지 대학을 졸업했을 것입니다.

(what I want )
Nice to meet you.
I'm Steve.
We had watched that movie before, so we knew the ending.
우리는 전에 그 영화를 보았으므로 결말을 알았습니다.

They had cleaned the house before their guests arrived.
그들은 손님이 도착하기 전에 집을 청소했습니다.

He had spoken to the manager about the issue earlier.
그는 이전 에이 문제에 대해 관리자에게 이야기했습니다.

They had played that game before, so they knew the rules
그들은 전에 그 게임을했기 때문에 규칙을 알았습니다.

By the end of the week, I will have completed this project.
주가 끝날 무렵, 나는이 프로젝트를 완료 할 것입니다.

She will have graduated from college by this time next year.
그녀는 내년 에이 시간까지 대학을 졸업했을 것입니다.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to display two lines from one lines.  Topic is solved

Post by swagfag » 17 Feb 2023, 11:49

to know what regex u need to write, u must first define what a sentence is

Code: Select all

text =
(LTrim Join`n
	Nice to meet you. I'm Steve.
	We had watched that movie before, so we knew the ending. 우리는 전에 그 영화를 보았으므로 결말을 알았습니다.

	They had cleaned the house before their guests arrived. 그들은 손님이 도착하기 전에 집을 청소했습니다.

	He had spoken to the manager about the issue earlier. 그는 이전 에이 문제에 대해 관리자에게 이야기했습니다.

	They had played that game before, so they knew the rules 그들은 전에 그 게임을했기 때문에 규칙을 알았습니다.

	By the end of the week, I will have completed this project. 주가 끝날 무렵, 나는이 프로젝트를 완료 할 것입니다.

	She will have graduated from college by this time next year. 그녀는 내년 에이 시간까지 대학을 졸업했을 것입니다.
)

MsgBox % text := RegExReplace(text, "\. ", ".`n") ; replace literaldot(as in "a period")-space with dot-LF (newline)
MsgBox % text := RegExReplace(text, "(\w) (\p{Hangul})", "$1`n$2") ; replace spaces between a normal char and a Hangul char with LF. look at the ", so they knew the rules " sentence

hancre
Posts: 251
Joined: 02 Jul 2021, 20:51

Re: How to display two lines from one lines.

Post by hancre » 18 Feb 2023, 02:48

swagfag wrote:
17 Feb 2023, 11:49
Oh, it works well. thanks for your help.

Can I have an additiona question?
My script works for most sentences. but it doesn't work for the last 3 lines.
I wonder what makes the difference.

gmoises
Posts: 75
Joined: 18 Nov 2017, 16:43

Re: How to display two lines from one lines.

Post by gmoises » 18 Feb 2023, 14:46

I have found some cases where a little delay is needed between statements
try:

Code: Select all

!r::
	Send, ^c
	Sleep, 50
	str:= Trim(Clipboard)
	Clipboard:=RegExReplace(str, "([\p{L}\p{N} ,-]+[\p{P}])\s*([\p{L}\p{N} .。、;!?]+[\p{P}]\S*)", "${1}`n${2}")
	Sleep, 50
	Send ^v
Return 

Also there is:
SetKeyDelay [, Delay, PressDuration, Play]
Sets the delay that will occur after each keystroke sent by Send or ControlSend.

hancre
Posts: 251
Joined: 02 Jul 2021, 20:51

Re: How to display two lines from one lines.

Post by hancre » 21 Feb 2023, 01:11

gmoises wrote:
18 Feb 2023, 14:46
thanks for your tip. ^^

I'll add 'sleep 50' for this and other cases. ^^

RussF
Posts: 1311
Joined: 05 Aug 2021, 06:36

Re: How to display two lines from one lines.

Post by RussF » 21 Feb 2023, 06:45

hancre wrote: My script works for most sentences. but it doesn't work for the last 3 lines.
I don't know regex very well, so I'm just shooting from the hip, but could it be that there is no period (.) after "rules" in the fourth line? Does your regex break when it can't find one?

Russ

hancre
Posts: 251
Joined: 02 Jul 2021, 20:51

Re: How to display two lines from one lines.

Post by hancre » 23 Feb 2023, 04:21

Oh.. got it. ^^;;

your point prevents the error.
Thank you for your help.

Post Reply

Return to “Ask for Help (v1)”