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 :
Func _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 by Busti, 06 June 2006 - 08:34 PM.





