pdug175 Posted February 20, 2006 Share Posted February 20, 2006 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? Link to comment Share on other sites More sharing options...
greenmachine Posted February 20, 2006 Share Posted February 20, 2006 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. Link to comment Share on other sites More sharing options...
Valuater Posted February 20, 2006 Share Posted February 20, 2006 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) Link to comment Share on other sites More sharing options...
greenmachine Posted February 20, 2006 Share Posted February 20, 2006 Or my way, which was much simpler. $SplitArray = StringSplit("Belfast (NI) 20th Feb - 21:06 Suspended", " - ", 1) MsgBox (0, "Time", StringLeft ($SplitArray[2], 5)) Link to comment Share on other sites More sharing options...
pdug175 Posted February 20, 2006 Author Share Posted February 20, 2006 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. Link to comment Share on other sites More sharing options...
Valuater Posted February 20, 2006 Share Posted February 20, 2006 Welcome to the Forums... Paul we enjoy helping people who make some effort like you!! 8) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now