LurchMan Posted December 15, 2010 Share Posted December 15, 2010 (edited) Hey everyone - I'm trying to take a string like such: 20080125071800 and turn it into 2008/01/25 07:18:00. The only problem is I'm horrible with StringFormat. Any help is appreciated, and possibly anywhere that might simplify this for next time. Thanks Lurch Edited December 15, 2010 by LurchMan Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end. Link to comment Share on other sites More sharing options...
Mat Posted December 15, 2010 Share Posted December 15, 2010 StringFormat won't do it... At least not without a few other functions. There are better ways but this gets it done: StringRegExpReplace($sInput, "(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})", "\1/\2/\3 \4:\5:\6") AutoIt Project Listing Link to comment Share on other sites More sharing options...
LurchMan Posted December 15, 2010 Author Share Posted December 15, 2010 Thank you! RegEx is still way above my level but maybe some day. Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end. Link to comment Share on other sites More sharing options...
iamtheky Posted December 15, 2010 Share Posted December 15, 2010 Here's a worse way to do it $string = 20080125071800 $split = StringSplit ($string , "" , 2) $new = $split[0] & $split[1] & $split[2] & $split[3] & "/" & $split[4] & $split[5] & "/" & $split[6] & $split[7] & " " & $split[8] & $split[9] & ":" & $split[10] & $split[11] & ":" & $split[12] & $split[13] msgbox (0, '' , $new) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Malkey Posted December 16, 2010 Share Posted December 16, 2010 .... I'm horrible with StringFormat. .... Here is a couple of better or worst methods (ways) StringFormat orientated. $string = 20080125071800 $sNewString = StringLeft($string, 4) & "/" & StringMid($string, 5, 2) & "/" & StringMid($string, 7, 2) & " " & _ StringMid($string, 9, 2) & ":" & StringMid($string, 11, 2) & ":" & StringRight($string, 2) ; Or $sNewStringFormat = StringFormat("%04d/%02d/%02d %02d:%02d:%02d", StringLeft($string, 4), StringMid($string, 5, 2), _ StringMid($string, 7, 2), StringMid($string, 9, 2), StringMid($string, 11, 2), StringRight($string, 2)) MsgBox(0, 'Result', "$sNewString = " & @TAB & $sNewString & @CRLF & "$sNewStringFormat = " & @TAB & $sNewStringFormat) ;Results ;2008/01/25 07:18:00 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