Jump to content

Stringsplit And Multiple Delimiters

Recommended Posts

I'm attempting to use StringSplit on a line such as "z:\\TMG93\techelp\H22562", however I need to be able to split the string after the \\ and the first \. I've tried the command $drives = StringSplit($line, "\\\"), but it splits the string exactly the same as $drives = StringSplit($line, "\\"). Is there any way of specifying multiple delimiters in a case such as this?



Link to post
Share on other sites

StringSplit supports multiple single-char delimiters, but it does not support multi-char delimiters..... (The help file remarks and example for StringSplit should make some mention of this, but it's easy to overlook)

You would need to first replace the "\\" with a single character such as * or ? or | or any other character guarranteed to not appear in a file name.

$line = StringReplace("z:\\TMG93\techelp\H22562", "\\", "?")
$drives = StringSplit($line, "\?");multiple single-char separators

or you could combine the StringReplace and StringSplit

and I think you could simply replace \\ with \

$drives = StringSplit(StringReplace("z:\\TMG93\techelp\H22562", "\\", "\"), "\")

Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to post
Share on other sites
  • Developers

You could do it this way

$I = "z:\\TMG93\techelp\H22562"
$S = StringTrimLeft($I,StringInStr($i,"\\")+1)
$S = StringLeft($S,StringInStr($s,"\")-1)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
Live for the present,
Dream of the future,
Learn from the past.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...