Split a single line of text to multiline Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
vsub
Posts: 541
Joined: 29 Sep 2015, 03:39

Split a single line of text to multiline

27 Sep 2021, 10:35

If I have a long single line of text,how can I convert it to multi line
For example

something --something1 --something2 --something3
I want to get this result back to the clipboard

something
--something1
--something2
--something3

-- determines that a new line need to be done
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Split a single line of text to multiline  Topic is solved

27 Sep 2021, 10:38

One way:

Code: Select all

input := "something --something1 --something2 --something3"

output := RegExReplace(input, "\s*--", "`n--")
MsgBox, % output
vsub
Posts: 541
Joined: 29 Sep 2015, 03:39

Re: Split a single line of text to multiline

27 Sep 2021, 10:42

RegEx...something I don't understand
Thanks,works fine
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Split a single line of text to multiline

27 Sep 2021, 10:43

You're welcome. Here's code to automatically check new contents of the clipboard and split it and place it back on the clipboard:

Code: Select all

#Persistent
OnClipboardChange("SplitLines")
return

SplitLines() {
	if !InStr(Clipboard, "--")
		return
	OnClipboardChange("SplitLines", 0)
	Clipboard := RegExReplace(Clipboard, "\s*--", "`n--")
	OnClipboardChange("SplitLines", 1)
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Joey5, mcd, NullRefEx and 126 guests