Sign in to follow this  
Followers 0
pdug175

extract a string

6 posts in this topic

Hi I want to extract the time from a number of strings like the one below:

Belfast (NI) 20th Feb - 21:06 Suspended

The problem that I have is that the strings don't follow any uniform pattern, so to strip x chars from the left or the right, or use stringreplace to remove Suspended and then grab the 5 rightmost characters wouldn't work as each string is slightly different. Would there be a way to strip everything up to and including the - char (as the time is always proceeded with a -) and then use Stringleft to determine the time?

Share this post


Link to post
Share on other sites



You could do stringleft or stringtrimleft in a for loop until the - is reached, or you could do it an easier method and use StringSplit.

$SplitArray = StringSplit("Belfast (NI) 20th Feb - 21:06 Suspended", " - ", 1)

This will return an array containing the split string. $SplitArray[0] will equal 2 (number of sections), $SplitArray[1] will be the left section up to the split, and $SplitArray[2] will be "21:06 Suspended" - you can get the time from there.

Share this post


Link to post
Share on other sites

maybe

$String = "Belfast (NI) 20th Feb - 21:06 Suspended"

$result = StringInStr( $String, "-")

$result1 = StringTrimLeft($String, $result + 1)

$result2 = StringLeft( $result1, 5)

MsgBox(0, "Your String is:", $result2)

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Or my way, which was much simpler.

$SplitArray = StringSplit("Belfast (NI) 20th Feb - 21:06 Suspended", " - ", 1)
MsgBox (0, "Time", StringLeft ($SplitArray[2], 5))

Share this post


Link to post
Share on other sites

Thanks again great help here on these forums.

Think it's a bit rude of me not to introduce myself! My name's Paul I'm from the UK, I've used autoit before in the past and I'm currently working on a script to collate and analyse data from my betfair account. I have done abit of programming in the past and thought I'd give this ago while I have a bit of time in the evenings. :o

Share this post


Link to post
Share on other sites

Welcome to the Forums... Paul

we enjoy helping people who make some effort

like you!!

8)


NEWHeader1.png

Share this post


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
Sign in to follow this  
Followers 0