WTS Posted July 20, 2006 Share Posted July 20, 2006 (edited) Hi there, i'm trying to remove unwanted strings such as command line parameters, and unneeded lines e.g. "C:\Program Files\Program Files\oot\loctus.exe""C:\Program Files\Program Files\oot\loctus.exe /c /tray""C:\Program Files\Program Files\oot\eyeballs_exp.exe /slow -rate 800"I really need to return this insteadC:\Program Files\Program Files\oot\loctus.exeC:\Program Files\Program Files\oot\loctus.exeC:\Program Files\Program Files\oot\eyeballs_exp.exedoes anyone know how to do this? Edited July 20, 2006 by WTS Link to comment Share on other sites More sharing options...
Helge Posted July 20, 2006 Share Posted July 20, 2006 picture.exe with spaces.jpgThe above text is a perfectly valid filename, but how to script this so that thescript understand where exactly the filename ends and the parameters begin ?This is something I had to troubles with a while back ago, and I can't really seehow it can be done now either. We could play with the string and do somechecking if it could find a string that actually was a file, but what if "picture.exe"was also a filename ?Btw, I'm not trying to topic-nap this, I'm just sharing my thoughts. Link to comment Share on other sites More sharing options...
WTS Posted July 20, 2006 Author Share Posted July 20, 2006 (edited) Hi helge, nice to know i'm not the only one [edit] i think were on the same page i came up with this.. but it doesn't trim all the unecessary strings ConsoleWrite(_StringRemoveBounding('"C:\Program Files\Program Files\oot\loctus.exe"')&@LF) ConsoleWrite(_StringRemoveBounding('"C:\Program Files\Program Files\oot\loctus.exe /c /tray"')&@LF) ConsoleWrite(_StringRemoveBounding('"C:\Program Files\Program Files\oot\eyeballs_exp.exe /slow -rate 800"')&@LF) Func _StringRemoveBounding($Str,$Opt=1) Local $StrRep,$StrFix,$chk If StringRegExp ($Str, '"') = 1 Then $StrFix = StringTrimRight(StringTrimLeft(StringReplace($Str,'"' & '"', ''),1),1) If StringRegExp ($Str, '/') = 1 Then $chk = StringSplit($StrFix , '/') $StrRep = $chk[UBound($chk) - 1] $StrFix = StringReplace($StrFix,$StrRep,'') EndIf Else $StrFix = $Str EndIf If Not @Error Then Return $StrFix EndFunc Edited July 20, 2006 by WTS Link to comment Share on other sites More sharing options...
Xenobiologist Posted July 20, 2006 Share Posted July 20, 2006 Hi, not very clever soultion, but maybe it helps out. ConsoleWrite(_StringRemoveBounding('"C:\Program Files\Program Files\oot\loctus.exe"') & @LF) ConsoleWrite(_StringRemoveBounding('"C:\Program Files\Program Files\oot\loctus.exe /c /tray"') & @LF) ConsoleWrite(_StringRemoveBounding('"C:\Program Files\Program Files\oot\eyeballs_exp.exe /slow -rate 800"') & @LF) ConsoleWrite(_StringRemoveBounding('picture.exe') & @LF) Func _StringRemoveBounding($s_Filename) Local $c = StringReplace(StringReplace($s_Filename, '"', ""), "'", "") Local $a = StringSplit($c, "\") If StringInStr($a[$a[0]], " ") <> 0 Then Return StringLeft($c,StringInStr($c, "\", -1, $a[0]-1)) & StringLeft($a[$a[0]], StringInStr($a[$a[0]], " ")) Else Return $c EndIf EndFunc ;==>_StringRemoveBounding So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
WTS Posted July 20, 2006 Author Share Posted July 20, 2006 (edited) well i think so, just as long as it works.. thanks th.meger Edited July 20, 2006 by WTS Link to comment Share on other sites More sharing options...
Simucal Posted July 21, 2006 Share Posted July 21, 2006 (edited) Behold the power of Regular Expressions!Global $s_Test[6] $s_Test[1] = "C:\Program Files\Program Files\oot\loctus.exe" $s_Test[2] = "C:\Program Files\Program Files\oot\l oct us.exe /c /tray" $s_Test[3] = "C:\Program Files\Program Files\oot\eyeballs_exp.exe /slow -rate 800" $s_Test[4] = "F:\This_is_ a file name\weee look - at - me.exe haha this wont show up" $s_Test[5] = "C:\this one.exe is for helge.jpg -rate 800" For $i=1 to Ubound($s_Test) -1 $a_Result = StringRegExp($s_Test[$i], '([A-Za-z]:\\.*\.[A-Za-z0-9]{3})',1) ConsoleWrite($a_Result[0]&@CRLF) Next Edited July 21, 2006 by Simucal AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc) Link to comment Share on other sites More sharing options...
Xenobiologist Posted July 21, 2006 Share Posted July 21, 2006 Hi Simucal,I like your affinity to StringRegExp. Because it takes me always a bit longer to figure out the right pattern, I'm always going the easy way with the standard funcs. Your func seems to work quite well. I just found one little mistake.You have to change this:$a_Result = StringRegExp($s_Test[$i], '([A-Za-z]:\\.*\.[A-Za-z0-9]{3})',1)into this$a_Result = StringRegExp($s_Test[$i], '([A-Za-z]:\\.*\.[A-Za-z0-9]{0})',1)Otherwise the func will cut file extensions after 3 letters.So :Global $s_Test[6] $s_Test[1] = "C:\Program Files\Program Files\oot\loctus.exe" $s_Test[2] = "C:\Program Files\Program Files\oot\l oct us.properties /c /tray" $s_Test[3] = "C:\Program Files\Program Files\oot\eyeballs_exp.exe /slow -rate 800" $s_Test[4] = "F:\This_is_ a file name\weee look - at - me.exe haha this wont show up" $s_Test[5] = "C:\this one.exe is for helge.jpg -rate 800" For $i= 1 To UBound($s_Test)-1 ConsoleWrite($i & ": " &_StringRemoveBounding($s_Test[$i]) &@CRLF ) Next Func _StringRemoveBounding($s_Filename) $a_Result = StringRegExp($s_Test[$i], '([A-Za-z]:\\.*\.[A-Za-z0-9]{0})',1) Return($a_Result[0]) EndFuncSo long,Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times 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