Sign in to follow this  
Followers 0
WTS

remove unwanted strings?

7 posts in this topic

#1 ·  Posted (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 instead

C:\Program Files\Program Files\oot\loctus.exe

C:\Program Files\Program Files\oot\loctus.exe

C:\Program Files\Program Files\oot\eyeballs_exp.exe

does anyone know how to do this?

Edited by WTS

Share this post


Link to post
Share on other sites



picture.exe with spaces.jpg

The above text is a perfectly valid filename, but how to script this so that the

script 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 see

how it can be done now either. We could play with the string and do some

checking 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.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi helge, nice to know i'm not the only one

[edit] i think were on the same page :D

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 by WTS

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

well i think so, just as long as it works.. :D

thanks th.meger

Edited by WTS

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 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)

Share this post


Link to post
Share on other sites

Hi Simucal,

I like your affinity to StringRegExp. :D 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. :wacko:

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])
EndFunc

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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0