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.
Need help dissecting multiline text from the Clipboard
- AlphaBravo
- Posts: 586
- Joined: 29 Sep 2013, 22:59
Re: Need help dissecting multiline text from the Clipboard
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
- flyingDman
- Posts: 2822
- Joined: 29 Sep 2013, 19:01
Re: Need help dissecting multiline text from the Clipboard
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
Re: Need help dissecting multiline text from the Clipboard
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
Re: Need help dissecting multiline text from the Clipboard
ABSOLUTELY amazing
Thanks guys!
All the code sets look great.
I'll use the first one you guys gave.
Thanks guys!
All the code sets look great.
I'll use the first one you guys gave.