Create a variable from a string inside special character. Simple?

Get help with using AutoHotkey and its commands and hotkeys
User avatar
eblanc
Posts: 71
Joined: 08 May 2019, 14:41

Create a variable from a string inside special character. Simple?

05 Mar 2020, 15:38

Hi coders of the world! I have a lot of different scripts that basically do one thing, so I'm trying to merge them into one ULTIMATE SCRIPT!!!

So at work, we have hundreds of databases. Arranged by state, and a reference ID. Here are 5 examples:

Code: Select all

userinput:
;Any of this would work as userinput

CA61 - 65685 - Dunder miffin company - some street birch ave
TX31 - 77785 - Cow, boy and hide company - 666 boots street
MEX15 - 12345 - Mexican resort - 44 fancy street, Tijuana, MX
DC99 - 58559 - Generic Corporate Business Name - 55-405 Weird street address that you'll likely forget by the end of this sentence.
BRZ88 - 123456 - Local Brewery company - 24-7 Because I'm thirsty street, party it up. Brazil.
So as you can see the first two "strings" are always pretty similar. 4-5 State/country code. And reference number is usually 5 digits, but can also be 6 digits sometimes!!!

Currently I have this kind of thing:

Code: Select all

CODE1:=SubStr(userinput,1,4)
REF1:=SubStr(userinput, 9, 5)


or

Code: Select all

CODE1:=SubStr(userinput,1,5)
REF1:=SubStr(userinput, 9, 5)


or

Code: Select all

CODE1:=SubStr(userinput,1,5)
REF1:=SubStr(userinput, 9, 6)


I have 3 different scripts for the same.

I'm wondering if instead of using Subst userinput.

I could use something to detect the "-" symbosl and spaces, and just grab whatever number is in between.

CODE1= Whatever number is before the "-" and space symbol (" -")
REF1 = Whatever number is in between both hypens and spaces ("- ") and (" -")

Yeah, just wondering how would I ago about this, I'm sure it's super simple, but wanted to do a good job of explaining. Once that is set, I can implent that change to EVERYTHING IVE SCRIPTED!!!!!

Well at least like 20-40% for sure.

First one to answer gets a cookie!!! :cookie:

Thanks!!!!
User avatar
boiler
Posts: 6629
Joined: 21 Dec 2014, 02:44

Re: Create a variable from a string inside special character. Simple?

05 Mar 2020, 16:01

Code: Select all

DB =
(
CA61 - 65685 - Dunder miffin company - some street birch ave
TX31 - 77785 - Cow, boy and hide company - 666 boots street
MEX15 - 12345 - Mexican resort - 44 fancy street, Tijuana, MX
DC99 - 58559 - Generic Corporate Business Name - 55-405 Weird street address that you'll likely forget by the end of this sentence.
BRZ88 - 123456 - Local Brewery company - 24-7 Because I'm thirsty street, party it up. Brazil.
)
Records := {}
Entries := StrSplit(DB, "`n", "`r")
for Each, Entry in Entries {
	Strings := StrSplit(Entry, " - ")
	Records.Push({"CODE1": Strings.1, "REF1": Strings.2, "Name": Strings.3, "Address": Strings.4})

}

; display data:
for Each, Record in Records
	TextOut .= Record.CODE1 "`n" Record.REF1 "`n" Record.Name "`n" Record.Address "`n`n"
MsgBox, % TextOut

Return to “Ask For Help”

Who is online

Users browsing this forum: CotswoldsMaker and 55 guests