Jump to content

extract substring from string


Recommended Posts

if my string looks like this:

$string = "joe/bob/mathew/john"

and i do:

StringSplit($string, "/")

how do i extract the last substring (in this case john) i got from stringsplitting the above string using the searchstring "/"

Edited by Hypertrophy
Link to comment
Share on other sites

StringSplit puts the substrings it finds in an array, with the total number stored in array element 0. So:

#include <String.au3>

Dim $stringarray[100]

$string = "joe/bob/mathew/john"
$stringarray=StringSplit($string,"/")
MsgBox(0,"",$stringarray[$stringarray[0]])
Link to comment
Share on other sites

You could also use UBound, it doesn't really matter much

$string = "joe/bob/mathew/john"
$array = StringSplit($string, "/")
MsgBox(0, "", $array[UBound($array)-1])
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...