AutID Posted October 14, 2016 Posted October 14, 2016 (edited) Hello, I have a string where I need to extract the time from it. I am currently doing it with StringSplit but I'd love to see other versions. Here is my way. Local $sText = '2016/10/14 07:31:09">07:31' Local $sSplit = StringSplit($sText, ':') MsgBox(0, "", StringRight($sSplit[1], 2) & ":" & $sSplit[2] & ":" & StringLeft($sSplit[3], 2)) Anyone who has time to share some other knowledge is welcome. Edit: I would like to see some regex version of it, not StringSplit versions Edit2: Another way here: Local $sText = '2016/10/14 07:31:09">07:31' Local $sSplit = _StringBetween($sText, ' ', '"')[0] MsgBox(0, "", $sSplit) Edited October 14, 2016 by AutID https://iblockify.wordpress.com/
UEZ Posted October 14, 2016 Posted October 14, 2016 As I'm not a regex expert: Local $sText = '2016/10/14 07:31:09">07:31' MsgBox(0, "", StringRegExpReplace($sText, '.*\h(.+?)".*', "$1")) AutID 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Danyfirex Posted October 14, 2016 Posted October 14, 2016 (edited) Hello. another example from a no regexp expert. Local $sText = '2016/10/14 07:31:09">07:31' MsgBox(0, "", _GetTime($sText)) Func _GetTime($String) Local $aReg = StringRegExp($String, '([0-9]+):([0-5][0-9]):([0-5][0-9])', 2) Return UBound($aReg) ? $aReg[0] : "" EndFunc ;==>_GetTime Saludos Edited October 14, 2016 by Danyfirex AutID 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
iamtheky Posted October 14, 2016 Posted October 14, 2016 one more, no regexp Local $sText = '2016/10/14 07:31:09">07:31' msgbox(0, '' , stringsplit(StringSplit($sText, ' ' , 2)[1] , '"' , 2)[0])) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
Muhammad_Awais_Sharif Posted October 14, 2016 Posted October 14, 2016 here is my version Local $sText = '2016/10/14 07:31:09">07:31' Local $Time = StringRegExp($sText, '\d{1,2}\:\d{1,2}\:\d{1,2}',1); MsgBox(0, "", $Time[0])
genius257 Posted October 14, 2016 Posted October 14, 2016 #include <Array.au3> Local $sText = '2016/10/14 07:31:09">07:31' $aArray = StringRegExp($sText, "([0-9]{4})/([0-9]{2})/([0-9]{2})[\s]+([0-9]{2}):([0-9]{2}):([0-9]{2})", 1) _ArrayDisplay($aArray) MsgBox(0, "", "DD/MM/YYYY:"&@TAB&$aArray[2]&"/"&$aArray[1]&"/"&$aArray[0]&@CRLF&"HH:MM:SS:"&@TAB&$aArray[3]&":"&$aArray[4]&":"&$aArray[5]) To show your appreciation My highlighted topics: AutoIt Package Manager, AutoItObject Pure AutoIt, AutoIt extension for Visual Studio Code Github: AutoIt HTTP Server, AutoIt HTML Parser
mikell Posted October 14, 2016 Posted October 14, 2016 So many ways to skin this cat ... Local $sText = '2016/10/14 07:31:09">07:31' Local $s = StringRegExp($sText, '\H+(?=")', 1) MsgBox(0, "", $s[0])
Gianni Posted October 14, 2016 Posted October 14, 2016 Local $sText = '2016/10/14 07:31:09">07:31' MsgBox(0, "", StringMid($sText, 12, 8)) Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
corgano Posted October 19, 2016 Posted October 19, 2016 (edited) I'm totally going to flog Regexr.com here. This tool is absolutely brilliant for learning / testing regex. See this example: http://regexr.com/3efm3 Edited October 19, 2016 by corgano 0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e
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