James Posted April 18, 2008 Share Posted April 18, 2008 Hi, Another snippet I had from over my AutoIting. I know StringReplace() can do the same thing, but it's always nice to see people using their intuition isn't it ConsoleWrite(_StringStripChr("AutoIt3 for the win!", "o") & @CRLF) Func _StringStripChr($from, $what) $StripOut = $From For $i = 1 To StringLen($what) $StripOut = StringReplace($StripOut, StringMid($what, $i, 1), "") Next Return $StripOut EndFunc James Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
martin Posted April 18, 2008 Share Posted April 18, 2008 Hi, Another snippet I had from over my AutoIting. I know StringReplace() can do the same thing, but it's always nice to see people using their intuition isn't it ConsoleWrite(_StringStripChr("AutoIt3 for the win!", "o") & @CRLF) Func _StringStripChr($from, $what) $StripOut = $From For $i = 1 To StringLen($what) $StripOut = StringReplace($StripOut, StringMid($what, $i, 1), "") Next Return $StripOut EndFunc James That is really awful A replacement for StringReplace that uses StringReplace and even then doesn't work. _StringStrip("anything you like at all because it makes no differenc","the quick brown fox jumps over the lazy dog") returns not a lot I would expect. $stripout = $from seems redundant; why not just use $from? But apart from that it's great. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
James Posted April 18, 2008 Author Share Posted April 18, 2008 Well I do sort of suck at AutoIt! Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
MrCreatoR Posted April 19, 2008 Share Posted April 19, 2008 (edited) This what i am expecting from such function: expandcollapse popup$String = ", ,C:Some dirSome File,," $Strip_Results = _StringStripChars($String, ", ", 3, 0, 1) ;3 = Strip from the both sides $Strip_Results = StringFormat("$Strip_Results = %sn@extended = %d", $Strip_Results, @extended) ConsoleWrite($Strip_Results) ;=============================================================================== ; Function Name: _StringStripChars() ; Description: Strip (replace) certain character(s) from the String. ; ; Parameter(s): $sString - String that character(s) will be striped from. ; $sSubString - The character(s) to strip. ; $iFlag [Optional] - Defines the behaviour of stripping process (see Returned value(s)). ; $iCount [Optional] - Defines how many times to perform the strip (see Returned value(s)). ; $iGroupChars [Optional] - If this parameter is 1 (default is 0), then all characters in $sSubString grouped and replaced seperately. ; ; Requirement(s): AutoIt 3.2.8.1 + ; ; Return Value(s): On seccess - Return new string with stripped characters accourding to given $Flag and $iCount: ; $iFlag = 0 (default) replace the character(s) in $sString whetewer it founded - with this flag, ; also @extended is set to number of $sSubString replaces in $sString. ; $iFlag = 1 replace the character(s) from the Left side of $sString. ; $iFlag = 2 replace the character(s) from the Right side of $sString. ; $iFlag = 3 replace the character(s) from the Bouth sides of $sString. ; ; $iCount = 0 replace all $sSubString char(s). ; $iCount > 0 replace that much $sSubString char(s). ; ; On failure - If lenght of given string is equel 0, then @error set to 1 and returned initial $sString. ; ; Author(s): amel27, mod. by G.Sandler a.k.a MsCreatoR ;=============================================================================== Func _StringStripChars($sString, $sSubString, $iFlag = 0, $iCount = 0, $iGroupChars = 0) If StringLen($sString) = 0 Then Return SetError(1, 0, $sString) Local $sGroupChar_a = '(', $sGroupChar_b = ')' If $iCount < 0 Then Local $sGroupChar_a = '[', $sGroupChar_b = ']' $sSubString = StringRegExpReplace($sSubString, '([][{}()|.?+*^$])', '1') If $iGroupChars = 1 Then $sSubString = '[' & $sSubString & ']' Local $sPattern = '(?i)' & $sGroupChar_a & $sSubString & $sGroupChar_b Local $sPattern_Count = '{1,' & $iCount & '}' If $iCount <= 0 Then $sPattern_Count = '+' If $iFlag <> 0 Then $iCount = 0 If $iFlag = 1 Then $sPattern = '(?i)^' & $sGroupChar_a & $sSubString & $sGroupChar_b & $sPattern_Count If $iFlag = 2 Then $sPattern = '(?i)' & $sGroupChar_a & $sSubString & $sGroupChar_b & $sPattern_Count & '$' If $iFlag = 3 Then $sPattern = '(?i)^' & $sGroupChar_a & $sSubString & $sGroupChar_b & $sPattern_Count & '|' & _ $sGroupChar_a & $sSubString & $sGroupChar_b & $sPattern_Count & '$' $sString = StringRegExpReplace($sString, $sPattern, '', $iCount) Return SetExtended(@extended, $sString) EndFunc Edited January 16, 2012 by MrCreatoR Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
martin Posted April 19, 2008 Share Posted April 19, 2008 Well I do sort of suck at AutoIt!Not at all, that's not true. If I thought that I wouldn't have been so hard on you. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
NELyon Posted April 19, 2008 Share Posted April 19, 2008 Yep, You Really Suck at Autoit @Creator:Niiiice. Link to comment Share on other sites More sharing options...
James Posted April 19, 2008 Author Share Posted April 19, 2008 Not at all, that's not true. If I thought that I wouldn't have been so hard on you. Thanks Martin! Yep, You Really Suck at Autoit Well, that was a lucky thing I guess, I mean it was being compared to work by others who have so much more experience - Disk Manager, one of the best pieces of work I have done in AutoIt, I'm still thinking of ideas and running test ideas to improve it. One idea is to be able to expand the GUI so that there is a listview with a selected partition/drives contents - Difficult!@Creator, that is a really good way of doing it, but I don't understand StringRegExp(), never have, anything that can help me?Thanks all! Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ 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