Need help dissecting multiline text from the Clipboard

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
omar
Posts: 545
Joined: 22 Oct 2015, 17:56

Need help dissecting multiline text from the Clipboard

14 Oct 2021, 20:23

I need some help dissecting text from multiple lines in the clipboard.

I will have something like this:

John Smith
123 Road Street
London
EX1 1AB
+44 7777212121

I want to store the last line in a variable X say and the rest in a variable called Y say.

Not sure the best way to do?
Store all in an array maybe?

Then... I want to grab the first name and store in a variable called Z
I guess I need some string manipulation here... which I've done before! But my mind isn't working straight right now!

+ One more big thing... I want to detect if after +44 above, if it's NOT a 7, I want to store a flag - so set a variable XYZ to be false or true.
Not sure where to start with this one at all!

Hoping someone can start me off!

Thanks.
User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: Need help dissecting multiline text from the Clipboard

14 Oct 2021, 21:07

Code: Select all

data =
(
John Smith
123 Road Street
London
EX1 1AB
+44 7777212121
)
line := StrSplit(Trim(data, "`r`n"), "`n", "`r")

MsgBox % x := line[line.Count()]
loop, % line.Count()-1
	y .= line[A_Index] "`n"
MsgBox % y
MsgBox % z := StrSplit(line.1, " ").1
xyz := (x ~= "\+44\s*7")
MsgBox % xyz
User avatar
flyingDman
Posts: 2821
Joined: 29 Sep 2013, 19:01

Re: Need help dissecting multiline text from the Clipboard

14 Oct 2021, 21:10

Or:

Code: Select all

var = 
(
John Smith
123 Road Street
London
EX1 1AB
+44 7777212121
)

msgbox % x := trim(substr(var,instr(var,"`n",,0,1)),"`n")
msgbox % y := trim(substr(var, 1, instr(var,"`n",,0,1)),"`n")
msgbox % xyz := instr(x,"+44 7")
14.3 & 1.3.7
sofista
Posts: 651
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: Need help dissecting multiline text from the Clipboard

15 Oct 2021, 12:42

Probably is an overkill, but if you want to play with arrays, something like this could work:

Code: Select all

Data = 
(
John Smith
123 Road Street
London
EX1 1AB
+44 7777212121
)

arrKeys := ["Name", "Address", "City", "Code", "Phone"]
arrValues := StrSplit(Data, "`n")
arrData := {}

For k, v in arrKeys {
	ArrData[arrKeys[A_Index]] := arrValues[A_Index]
}

MsgBox, % ArrData.Phone
MsgBox, % Format("{}`n{}`n{}`n{}", arrValues*)
MsgBox, % InStr(ArrData.Phone, "+44 7")
return
omar
Posts: 545
Joined: 22 Oct 2015, 17:56

Re: Need help dissecting multiline text from the Clipboard

20 Oct 2021, 06:45

ABSOLUTELY amazing
Thanks guys!
All the code sets look great.
I'll use the first one you guys gave.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Rohwedder and 269 guests