Busti Posted June 6, 2006 Share Posted June 6, 2006 (edited) hi , here my new udf, you can : search for a string, search for a string casesense, replace a string, replace a string casesense! commentet nearly all of the code, hope ya like it : udf : expandcollapse popupFunc _CaseSearchOrReplaceStr( $String , $SearchString="" , $ReplaceString="", $Mode=1 ,$Count="x") ;Mode's : ; ~ 1 = Search a String ; ~ 2 = Search a String Casesense ; ~ 3 = Replace a String ; ~ 4 = Replace a String Casesense Local $u_String = $String Local $s_String = $SearchString Local $r_String = $ReplaceString Local $u_Mode = $Mode Local $ReturnString = "" Dim $LenOfFoundString = 0,$LenOfSearchString = StringLen($s_String),$FoundCount=0 If ( $u_String = "" ) Or ( StringLen($u_String) < 1 ) Or ( StringLen($s_String) < 1 )Then SetError(1) Return -1 ; -1 = error in the strings ;Error in the Strings EndIf If $Count < 1 And $Count <> "x" Then SetError(2) Return -2 EndIf If ($Mode = 1) Or ($Mode = 2) Then ;~GetMode If $Mode = 1 Then ;~Split String $u_String = StringSplit($u_String," ") ;~Searchfor the Word For $i_Search = 1 To $u_String[0] ;~if is in string then return the word count, eg. ;~hello im back ;~searching for im,he will return 2 If StringInStr($u_String[$i_Search],$s_String,1) Then Return $i_Search EndIf Next ;~loop is done, nothing found Return 0 Else ;~Split the String $u_String = StringSplit($u_String," ") For $i_Search = 1 To $u_String[0] ;~if is in string then return the word count, eg. ;~hello imback ;~searching for im,he will return 0, becouse ;~it was not found -> casesense ! If StringInStr($u_String[$i_Search],$s_String,1) Then ;~Found String, Checking the Lengh of it. $LenOfFoundString = StringLen($u_String[$i_Search]) If $LenOfFoundString <> $LenOfSearchString Then ;~Do Nothing.. ;~Becouse its not our string we want! Else ;~Else Return number, as by Mode 1 Return $i_Search EndIf EndIf Next ;~loop is done, nothing found Return 0 EndIf ElseIf ($Mode = 3) Or ($Mode = 4) Then If $Mode = 3 Then ;~There is already a Function for this so... ;~i will save some work :D If StringInStr( $u_String, $s_String ) Then Return StringRegExpReplace( $u_String, $s_String, $r_String ) EndIf Return 0 Else ;~Split the String $u_String = StringSplit($u_String," ") If $Count = "x" Then $Count = $u_String[0] For $i_Search = 1 To $u_String[0] ;~if the string is found he checks the lengh of the ;~a) searchstring ;~B) replacestring ;~if the lengh matches, he replaces the word, ;~and returns the complete string. If StringInStr($u_String[$i_Search],$s_String,1) Then ;~Found String, Checking the Lengh of it. $LenOfFoundString = StringLen($u_String[$i_Search]) If $LenOfFoundString = $LenOfSearchString Then $FoundCount += 1 $u_String[$i_Search] = $ReplaceString If ($FoundCount = $Count) Or ($i_Search == $u_String[0]) Then ;~Makes the full string again, and returns it! For $i_RemakeString = 1 To $u_String[0] $ReturnString &= " " & $u_String[$i_RemakeString] Next Return $ReturnString EndIf Return 0 Else ;~Do Nothing.. ;~Becouse its not our string we want! EndIf EndIf Next ;~loop is done, nothing found Return 0 EndIf EndIf Return 0 EndFunc oÝ÷ ÙìZ^jëh×6 MsgBox(0,"",_CaseSearchOrReplaceStr( "Hello im ThereBO" , "BO" , -1, 1));search for a string MsgBox(0,"",_CaseSearchOrReplaceStr( "Hello im ThereBO" , "BO" , -1, 2));search casesense for a string MsgBox(0,"",_CaseSearchOrReplaceStr( "Hello im ThereBO" , "BO" , "omg dont lie!", 3));replace a string MsgBox(0,"",_CaseSearchOrReplaceStr( "Hello im ThereBO" , "BO" , "omg dont lie!", 4));replace a string casesense post some comments hope the name is okay @valik^^ Edited June 6, 2006 by Busti My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity Link to comment Share on other sites More sharing options...
w0uter Posted June 6, 2006 Share Posted June 6, 2006 (edited) why do you do Func _CaseSearchOrReplaceStr( $String , $SearchString="" , $ReplaceString="", $Mode=1 ,$Count="x") Local $u_String = $String Local $s_String = $SearchString Local $r_String = $ReplaceString Local $u_Mode = $ModeoÝ÷ Ú)ìµæ¡ö®¶sdgVæ2ô66U6V&6÷%&WÆ6U7G"b33c·Uõ7G&ærÂb33c·5õ7G&æsÒgV÷C²gV÷C²Âb33c·%õ7G&æsÒgV÷C²gV÷C²Âb33c·UôÖöFSÓÂb33c´6÷VçCÒgV÷C·gV÷C²oÝ÷ Ù©l¡«¢+رÍ(íù¼9½Ñ¡¥¹¸¸(íù ½ÕÍ¥Ñ̹½Ð½ÕÈÍÑÉ¥¹ÝݹÐÌÌoÝ÷ Ú+n+n±é^²Ëè(zÇè«¢+Ø%ÀÌØí1¹=½Õ¹MÑÉ¥¹±ÐìÐìÀÌØí1¹=MÉ¡MÑÉ¥¹Q¡¸(íù¼9½Ñ¡¥¹¸¸(íù ½ÕÍ¥Ñ̹½Ð½ÕÈÍÑÉ¥¹ÝݹÐÌÌì(±Í(íù±ÍIÑÕɸ¹ÕµÈ°Ìä5½Ä(IÑÕɸÀÌØí¥}MÉ (¹%oÝ÷ ÛÈhºW[zj+zX¤y«¢+Ù%ÀÌØí1¹=½Õ¹MÑÉ¥¹ôÀÌØí1¹=MÉ¡MÑÉ¥¹Q¡¸IÑÕɸÀÌØí¥}MÉ and for the last bash: why do you first decide between 1-2 & 3-4 and then 1-2 -> 1 & 2 and 3-4 -> 3 & 4 why not just make it one Switch statement ? (kinda blurry explanation i know) other then that it looks pretty decent. Edited June 6, 2006 by w0uter My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
Busti Posted June 6, 2006 Author Share Posted June 6, 2006 (edited) becouse if i want to change this variables : $String , $SearchString="" , $ReplaceString="", $Mode=1 ,$Count="x" i dont need to change them in the whole script rather useless but it saves some work, if i found a better way or forgot something example : i forgot the $replace array, i only needet to change my old name of $searchorreplace to $searchstring and 1 to $replace string, and i only needet to change 1 var insteat of 10 €dit: too your new edit, i wantet to make the function so tidy, that everyone can read it, i had some problems, where i startet to read it how you made €dit : thx, did you test it ? Edited June 6, 2006 by Busti My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity Link to comment Share on other sites More sharing options...
w0uter Posted June 6, 2006 Share Posted June 6, 2006 IMO preformence > readability sure edited that post alot eh i always do that but noone reads it as fast as you do. and no i did not test it since im booted from a live cd. My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
Busti Posted June 6, 2006 Author Share Posted June 6, 2006 (edited) i always do that but noone reads it as fast as you do. im always waiting, until ~10min or all leaved reading my topic hmm switch, alright ! Forgot to make it but looks nice with if dunno im always catching the first thing that is in my head pls test it if you can or want a exe ?i like much posts in my topic, thats why im looking in it^^ Edited June 6, 2006 by Busti My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity Link to comment Share on other sites More sharing options...
Busti Posted June 7, 2006 Author Share Posted June 7, 2006 *waiting4forposts:(* My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity Link to comment Share on other sites More sharing options...
Busti Posted June 7, 2006 Author Share Posted June 7, 2006 but its not casesense ! My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity Link to comment Share on other sites More sharing options...
JSThePatriot Posted June 7, 2006 Share Posted June 7, 2006 but its not casesense ! If you look at the end of his string of code you will see where it says [casesense]) That to me indicates the case sensitivity. JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 7, 2006 Moderators Share Posted June 7, 2006 I do that all the time!! Make a damn UDF that was already made because I didn't read every function option. 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...
Busti Posted June 7, 2006 Author Share Posted June 7, 2006 @js it wont work, dont know why, or it doesntwork for me, if i search for bo and my string is mybo then it replaces the bo at mybo, but he should not do that! My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity 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