Page 1 of 1

How to get SplitStr to find this " - "

Posted: 22 Apr 2024, 12:10
by Ragnar55
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

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

Posted: 22 Apr 2024, 13:12
by JoeWinograd
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

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

Posted: 22 Apr 2024, 14:02
by Ragnar55
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

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

Posted: 22 Apr 2024, 14:18
by JoeWinograd
You're very welcome, Ragnar, I'm glad that it works for you. Regards, Joe