Zisly Posted June 11, 2009 Share Posted June 11, 2009 (edited) Not sure if there already is a function like this.. Maybe this is something that could be added to the string UDF? ; #FUNCTION#;=============================================================================== ; ; Name...........: _String_Search ; Description ...: Checks if a string contains a given substring ; Syntax.........: _String_Search($string,$substring) ; Parameters ....: $string = string to evaluate ; $substring = substring to search for ; Return values .: Success - Returns a array containing the position of the found substrings. ; Failure - Returns 0 ; ; Author ........: Zisly ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; Yes ; ;;========================================================================================== Func _String_Search($string, $substring) StringReplace($string, $substring, '') $ac = @extended If $ac = 0 Then Return 0 Local $found[$ac] For $i = 1 To $ac $found[$i - 1] = StringInStr($string, $substring, 0, $i) Next Return $found EndFunc ;==>_String_Search Example: #include <Array.au3> #include <string.au3> $array = _String_Search('a b a c a' , 'a') _ArrayDisplay($array) Edited June 11, 2009 by Zisly Link to comment Share on other sites More sharing options...
Zedna Posted June 11, 2009 Share Posted June 11, 2009 (edited) Nice! Here is small/quick example #include <Array.au3> $array = _string_search('a b a c a' , 'a') _ArrayDisplay($array) Edited June 11, 2009 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zisly Posted June 11, 2009 Author Share Posted June 11, 2009 Nice! Here is small/quick example #include <Array.au3> $array = _string_search('a b a c a' , 'a') _ArrayDisplay($array)I find it weird that no one has made such a function yet Link to comment Share on other sites More sharing options...
AlmarM Posted June 11, 2009 Share Posted June 11, 2009 I once made this sort of thing for a File. But I only used it once. Nice though! Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
Valuater Posted June 11, 2009 Share Posted June 11, 2009 I just don't like the name.. Maybe StringInStrEx() 8) Link to comment Share on other sites More sharing options...
Zisly Posted June 11, 2009 Author Share Posted June 11, 2009 Feel free to change it, it's what it does thats important Added example Link to comment Share on other sites More sharing options...
ptrex Posted June 12, 2009 Share Posted June 12, 2009 @all Did anyone ever run this example ? Because it does not work correctly. Showing wrong output @Zisly You will have to do more efforts here. regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Xenobiologist Posted June 12, 2009 Share Posted June 12, 2009 @allDid anyone ever run this example ?Because it does not work correctly. Showing wrong output @ZislyYou will have to do more efforts here. regardsptrexWhy not? Maybe you forgot to count the spaces $array = _String_Search('abaca' , 'a')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...
Aasem Posted June 12, 2009 Share Posted June 12, 2009 Just wondering what is a Strong? And could String searching help me in Autoit problems? Like are stongs needed? Link to comment Share on other sites More sharing options...
Zisly Posted June 12, 2009 Author Share Posted June 12, 2009 (edited) @allDid anyone ever run this example ?Because it does not work correctly. Showing wrong output @ZislyYou will have to do more efforts here. regardsptrexIt counts the spaces also so there isn't anything wrong with the example.And what do you mean with "You will have to do more efforts here"? Edited June 12, 2009 by Zisly Link to comment Share on other sites More sharing options...
oMBRa Posted June 12, 2009 Share Posted June 12, 2009 Just wondering what is a Strong? And could String searching help me in Autoit problems? Like are stongs needed?what are Strong and stongs? Link to comment Share on other sites More sharing options...
Xenobiologist Posted June 13, 2009 Share Posted June 13, 2009 Hi, here ist somthing similar I did once. ;Umlaute Global $test = 'this is a test ÜÖÄ ||| üöä Test ü, ö, ä, ÄÖÜ :-(!' ConsoleWrite(_StringReplaceEx($test, 'Ü|Ö|Ä|ü|ö|ä|ß|(', 'Ue|Oe|Ae|ue|oe|ae|ss|)') & @CRLF) ConsoleWrite(_StringReplaceEx($test, 'Ü|CH', 'Ue|CH!') & @CRLF) ConsoleWrite(_StringReplaceEx($test, 'ch@|', '@', 2, 1, '@') & @CRLF) ;=============================================================================== ; Function Name: _StringReplaceEx ; Description:: Replace multiple Strings like StringReplace ; Parameter(s): Like StringReplace. $searchstring and $replacestring, $count, $case, $delim ; Requirement(s): --- ; Return Value(s): new string ; -1 = no | found ; -2 = string count do not match ; -3 = case should be 0,1,2 ; Author(s): Thorsten Meger (Xenobiologist) ;=============================================================================== Func _StringReplaceEx($string, $searchstring, $replacestring, $count = 0, $case = 0, $delim = '|') If Not StringInStr($searchstring, $delim) Or Not StringInStr($replacestring, $delim) Then Return -1 Local $searchstring_A = StringSplit($searchstring, $delim), $replacestring_A = StringSplit($replacestring, $delim) If UBound($searchstring_A) <> UBound($replacestring_A) Then Return -2 If $case < 0 Or $case > 2 Then Return -3 For $i = 1 To UBound($searchstring_A) - 1 $string = StringReplace($string, String($searchstring_A[$i]), String($replacestring_A[$i]), $count, $case) Next Return $string EndFunc ;==>_StringReplaceEx 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...
Moderators SmOke_N Posted June 13, 2009 Moderators Share Posted June 13, 2009 (edited) Since everyone is throwing in their two cents. StringReplace() (especially insensitive match/replace) is much slower than StringInStr() itself. And sense you'll be using it anyway, might try something like this:#include <array.au3>; Only for _ArrayDisplay() Global $s_str = "Sally sells sea shells down by the sea shore" ; Case sensitive match $a_array = _String_GetPosArray($s_str, "s", 1) _ArrayDisplay($a_array, "Sensitive match") ; Case in-sensitive match $a_array = _String_GetPosArray($s_str, "s") _ArrayDisplay($a_array, "In-sensitive match") Func _String_GetPosArray($s_str, $s_find, $v_case = 0) Local $i_c = 0, $i_pos = 0, $a_ret[100] = [100] While 1 $i_pos = StringInStr($s_str, $s_find, $v_case, 1, $i_pos + 1) If $i_pos = 0 Then ExitLoop $i_c += 1 If $i_c = $a_ret[0] Then ReDim $a_ret[$a_ret[0] + 100] $a_ret[0] = $a_ret[0] + 100 EndIf $a_ret[$i_c] = $i_pos WEnd If $i_c = 0 Then Return SetError(1, 0, 0) ReDim $a_ret[$i_c + 1] $a_ret[0] = $i_c Return $a_ret EndFunc For the RegEx junky's#include <array.au3>; Only for _ArrayDisplay() Global $s_str = "Sally sells sea shells down by the sea shore" ; Case sensitive match $a_array = _StringRegEx_GetPosArray($s_str, "s") _ArrayDisplay($a_array, "Sensitive match") ; Case in-sensitive match $a_array = _StringRegEx_GetPosArray($s_str, "(?i)s") _ArrayDisplay($a_array, "In-sensitive match") Func _StringRegEx_GetPosArray($s_str, $s_find) Local $i_pos = 0 Local $a_sre = StringRegExp($s_str, $s_find, 3) If @error Then Return SetError(1, 0, 0) Local $i_ub = UBound($a_sre) Local $a_ret[$i_ub + 1] = [$i_ub] For $i = 0 To $i_ub - 1 $i_pos = StringInStr($s_str, $a_sre[$i], 1, 1, $i_pos + 1) $a_ret[$i + 1] = $i_pos Next Return $a_ret EndFunc Edited June 13, 2009 by SmOke_N Removed var that wasn't being used Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. 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