NoizeBit Posted July 25, 2015 Posted July 25, 2015 Hi,I'd like to trim this line:ue="1001372">27/07 05:00<to look like this:27/07 05:00was using this until I've found out the numbers within the quotation marks are changing from time to time (sometimes there's one more number):StringTrimRight(StringTrimLeft('ue="1001372">27/07 05:00<', 13), 1)So how should I trim this string's left side starting from "u" till ">"?
Andreik Posted July 25, 2015 Posted July 25, 2015 You can try RegExp$var = 'ue="1001372">27/07 05:00<' MsgBox(0,'',Trim($var)) Func Trim($var) Local $match = StringRegExp($var,'(.*?)(\d{2})(\/)(\d{2})(\s)(\d{2})(:)(\d{2})',1) Local $result = '' If IsArray($match) Then For $i = 1 To UBound($match)-1 $result &= $match[$i] Next EndIf Return $result EndFunc NoizeBit 1
Gianni Posted July 25, 2015 Posted July 25, 2015 or also like this:$sString = 'ue="1001372">27/07 05:00<' ; $sOutput = StringLeft(StringRight($sString, 12), 11) ; MsgBox(0, 0, "Input:" & @TAB & $sString & @CRLF & "Out :" & @TAB & $sOutput) NoizeBit 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
NoizeBit Posted July 25, 2015 Author Posted July 25, 2015 On 7/25/2015 at 11:34 AM, Andreik said: You can try RegExp$var = 'ue="1001372">27/07 05:00<' MsgBox(0,'',Trim($var)) Func Trim($var) Local $match = StringRegExp($var,'(.*?)(\d{2})(\/)(\d{2})(\s)(\d{2})(:)(\d{2})',1) Local $result = '' If IsArray($match) Then For $i = 1 To UBound($match)-1 $result &= $match[$i] Next EndIf Return $result EndFunc Thanks Andreik, but I can't say I understand much from your code, but it's my fault, I'm just learning how to code
NoizeBit Posted July 25, 2015 Author Posted July 25, 2015 On 7/25/2015 at 11:39 AM, Chimp said: or also like this:$sString = 'ue="1001372">27/07 05:00<' ; $sOutput = StringLeft(StringRight($sString, 12), 11) ; MsgBox(0, 0, "Input:" & @TAB & $sString & @CRLF & "Out :" & @TAB & $sOutput) Thanks Chimp, this is more likely what I'd choose Isn't there an easier method which just simply deletes part of the string? It'll always start with "u" character and end with ">", but the string might change to just this: "05:00".
Gianni Posted July 25, 2015 Posted July 25, 2015 (edited) for sure some regex guru will provide a magic solution, anyway in the while this "workaround" could be quick a way. $sString = 'ue="1001372">27/07 05:00<' ; ConsoleWrite(StringReplace($sString, StringLeft($sString, StringInStr($sString, ">")), "") & @CRLF)edit:or this if the "u" char is not always at first position:$sString = 'ue="1001372">27/07 05:00<' ; ConsoleWrite(StringReplace($sString, StringMid($sString, StringInStr($sString, "u"), StringInStr($sString, ">")), "") & @CRLF) Edited July 25, 2015 by Chimp NoizeBit 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
Exit Posted July 25, 2015 Posted July 25, 2015 $before = 'ue="1001372">27/07 05:00<' $after = StringSplit($before, "<>")[2] MsgBox(262144, "Result", $before & @CRLF & $after, 0) NoizeBit 1 App: Au3toCmd UDF: _SingleScript()
NoizeBit Posted July 25, 2015 Author Posted July 25, 2015 On 7/25/2015 at 12:48 PM, Exit said: $before = 'ue="1001372">27/07 05:00<' $after = StringSplit($before, "<>")[2] MsgBox(262144, "Result", $before & @CRLF & $after, 0) Exactly what I was looking for, thanks
SadBunny Posted July 25, 2015 Posted July 25, 2015 Or _StringBetween...#include <String.au3> $before = 'ue="1001372">27/07 05:00<' $after = _StringBetween($before, ">", "<")[0] MsgBox(262144, "Result", $before & @CRLF & $after, 0) NoizeBit 1 Roses are FF0000, violets are 0000FF... All my base are belong to you.
NoizeBit Posted July 25, 2015 Author Posted July 25, 2015 On 7/25/2015 at 5:48 PM, SadBunny said: Or _StringBetween...#include <String.au3> $before = 'ue="1001372">27/07 05:00<' $after = _StringBetween($before, ">", "<")[0] MsgBox(262144, "Result", $before & @CRLF & $after, 0) Great, thanks
mikell Posted July 26, 2015 Posted July 26, 2015 (edited) Some regex...$before = 'ue="1001372">27/07 05:00<' $after = StringRegExpReplace($before, '.*>([^<]+).*', "$1") MsgBox(0, "Result1", $before & @CRLF & $after) ; this way works but will crash your script in case of error (same for SadBunny's code) $after = StringRegExp($before, '>([^<]+)', 3)[0] MsgBox(0, "Result2", $before & @CRLF & $after) ;error example: #include <String.au3> $before = 'ue="1001372">27/07 05:00' ; < is absent, so ... $after = _StringBetween($before, ">", "<")[0] ; ... no match causes AutoIt fatalll error ! MsgBox(262144, "Result", $before & @CRLF & $after, 0) Edited July 26, 2015 by mikell NoizeBit 1
NoizeBit Posted July 26, 2015 Author Posted July 26, 2015 On 7/26/2015 at 12:40 AM, mikell said: Some regex...$before = 'ue="1001372">27/07 05:00<' $after = StringRegExpReplace($before, '.*>([^<]+).*', "$1") MsgBox(0, "Result1", $before & @CRLF & $after) ; this way works but will crash your script in case of error (same for SadBunny's code) $after = StringRegExp($before, '>([^<]+)', 3)[0] MsgBox(0, "Result2", $before & @CRLF & $after) ;error example: #include <String.au3> $before = 'ue="1001372">27/07 05:00' ; < is absent, so ... $after = _StringBetween($before, ">", "<")[0] ; ... no match causes AutoIt fatalll error ! MsgBox(262144, "Result", $before & @CRLF & $after, 0) Thank you, I'll try this one out, too!
Gianni Posted July 26, 2015 Posted July 26, 2015 here one more way (are allowed also the presence of more groups on the source string, in this way you could extract all occurrences from a file in one shot)#include <array.au3> ; just to show result(s) Local $sOpen = ">", $sClose = "<" ; wanted Opening and Closing "delimiters" $sSoure = 'ue="1001372">27/07 05:00<' $aOut = StringRegExp($sSoure, "(?s)" & $sOpen & "(.*?)" & $sClose, 3) ; <- extraction if IsArray($aOut) Then _ArrayDisplay($aOut, "From first string") $sSoure = 'ue="1001372">27/07 05:00< ue=" 8013">28/07 04:00< ue=" 12345001372">29/07 03:00<the end' $aOut = StringRegExp($sSoure, "(?s)" & $sOpen & "(.*?)" & $sClose, 3) ; <- extraction if IsArray($aOut) Then _ArrayDisplay($aOut, "From second string") NoizeBit 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
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