How to get SplitStr to find this " - " Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Ragnar55
Posts: 2
Joined: 22 Apr 2024, 12:02

How to get SplitStr to find this " - "

22 Apr 2024, 12:10

Hello, i am trying to make code to split a folder name for instance "Sampletekk - ARP Solina" into two parts.
First part being stuff before " - " and second part being everything after it.

But i cannot make it find the: space dash space " - " part.
If i split from "-" this sign , it doesnt work because some folder names contain that on several occasions
User avatar
JoeWinograd
Posts: 2209
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: How to get SplitStr to find this " - "  Topic is solved

22 Apr 2024, 13:12

Hi Ragnar,
I see that this is your first post here, so let me start with...Welcome Aboard!
Ragnar55 wrote:How to get SplitStr to find this " - "
The function is StrSplit, not SplitStr.
Ragnar55 wrote:it doesnt work because some folder names contain that on several occasions
I assume that you want the first part to be everything before the first " - ", and the second part to be everything after the first " - ", even if it has " - " strings in it. To achieve that, read the section called NaxParts in the StrSplit doc. With that in mind, here's some sample code:

Code: Select all

FolderName:="Sampletekk - ARP Solina - test - additional - hyphens"
Array:=StrSplit(FolderName," - ",,2) ; MaxParts=2
FirstPart:=Array[1]
SecondPart:=Array[2]
MsgBox % "1st=" FirstPart "`n2nd=" SecondPart
Regards, Joe
Ragnar55
Posts: 2
Joined: 22 Apr 2024, 12:02

Re: How to get SplitStr to find this " - "

22 Apr 2024, 14:02

JoeWinograd wrote:
22 Apr 2024, 13:12

Code: Select all

FolderName:="Sampletekk - ARP Solina - test - additional - hyphens"
Array:=StrSplit(FolderName," - ",,2) ; MaxParts=2
FirstPart:=Array[1]
SecondPart:=Array[2]
MsgBox % "1st=" FirstPart "`n2nd=" SecondPart
Regards, Joe

That works perfectly, thank you kind sir. This will end up helping more than just myself as i am trying to make this tool to help other people save time. Spent like 3 hours trying to get that part to work
User avatar
JoeWinograd
Posts: 2209
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: How to get SplitStr to find this " - "

22 Apr 2024, 14:18

You're very welcome, Ragnar, I'm glad that it works for you. Regards, Joe

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: just me, Rohwedder, zabbn and 118 guests