AlmarM Posted June 9, 2009 Posted June 9, 2009 Hi,I trying to make a new UDF called "_StringStripChar", and I could use some help.$String = "TEST!@#" $Test = _StringStripChar($String, "!@#") MsgBox(0, "", $Test) Func _StringStripChar($sString, $sChars) Local $vNothing = "" Local $sReturn = "" If StringLen($sChars) > 1 Then $sSplit = StringSplit($sChars, "") For $i = 1 To $sSplit[0] If $sSplit[$i] = $sSplit[$i] Then $sReturn = StringReplace($sString, $sSplit[$i], $vNothing) EndIf Next Else $sReturn = StringReplace($sString, $sChars, $vNothing) EndIf Return $sReturn EndFuncAs you can see im using TEST!@# and a strip with !@#.But if you run this, you'll see it returns TEST!@, it just stripped out the last char.Does anyone have any idea? AlmarM 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.
Valuater Posted June 9, 2009 Posted June 9, 2009 Maybe.. $String = "TEST!@#" $Test = _StringStripChar($String, "!@#") MsgBox(0, "", $Test) Func _StringStripChar($sString, $sChars) Local $vNothing = "" Local $sReturn = "" If StringLen($sChars) > 1 Then $sSplit = StringSplit($sChars, "") For $i = 1 To $sSplit[0] If StringInStr($sString, $sSplit[$i]) Then $sString = StringReplace($sString, $sSplit[$i], $vNothing) EndIf Next Return $sString Else $sReturn = StringReplace($sString, $sChars, $vNothing) EndIf Return $sReturn EndFunc 8)
AlmarM Posted June 9, 2009 Author Posted June 9, 2009 (edited) Ah, fixed it. A little test: expandcollapse popup$Start_A1 = TimerInit() $AlmarM1 = _StringStripChar("t1e1s1t1", "1") $Stop_A1 = TimerDiff($Start_A1) $Start_A2 = TimerInit() $AlmarM2 = _StringStripChar("t12e12s12t12", "12") $Stop_A2 = TimerDiff($Start_A2) $Start_V1 = TimerInit() $Valuater1 = _StringStripCharEx("t1e1s1t1", "1") $Stop_V1 = TimerDiff($Start_V1) $Start_V2 = TimerInit() $Valuater2 = _StringStripCharEx("t12e12s12t12", "12") $Stop_V2 = TimerDiff($Start_V2) MsgBox(0, "AlmarM #1", $AlmarM1 & @CRLF & $Stop_A1) MsgBox(0, "AlmarM #2", $AlmarM2 & @CRLF & $Stop_A2) MsgBox(0, "Valuater #1", $Valuater1 & @CRLF & $Stop_V1) MsgBox(0, "Valuater #2", $Valuater2 & @CRLF & $Stop_V2) Func _StringStripChar($sString, $sChars) ; AlmarM Local $vNothing = "" If StringLen($sChars) > 1 Then $sSplit = StringSplit($sChars, "") For $i = 1 To $sSplit[0] If $sSplit[$i] = $sSplit[$i] Then $sString = StringReplace($sString, $sSplit[$i], $vNothing) EndIf Next Else $sString = StringReplace($sString, $sChars, $vNothing) EndIf Return $sString EndFunc Func _StringStripCharEx($sString, $sChars) ; Valuater Local $vNothing = "" If StringLen($sChars) > 1 Then $sSplit = StringSplit($sChars, "") For $i = 1 To $sSplit[0] If StringInStr($sString, $sSplit[$i]) Then $sString = StringReplace($sString, $sSplit[$i], $vNothing) EndIf Next Return $sString Else $sString = StringReplace($sString, $sChars, $vNothing) EndIf Return $sString EndFunc AlmarM Edited June 9, 2009 by AlmarM 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.
Valuater Posted June 9, 2009 Posted June 9, 2009 Ok, I didn't say anything the first time... but If $sSplit[$i] = $sSplit[$i] Then what the hell is that?? 8)
AlmarM Posted June 9, 2009 Author Posted June 9, 2009 Ok, I didn't say anything the first time... but If $sSplit[$i] = $sSplit[$i] Then what the hell is that?? 8)Well, after some thinking, if $sSplit[1] = the first splitted char... Etc. I had some trouble finding it out... But it works 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.
Valuater Posted June 9, 2009 Posted June 9, 2009 Well, after some thinking, if $sSplit[1] = the first splitted char... Etc. I had some trouble finding it out... But it works If you remove that, it will still work... It doesn't do anything 8)
AlmarM Posted June 9, 2009 Author Posted June 9, 2009 If you remove that, it will still work... It doesn't do anything8)Oh, geez. Stupid me >.<' 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.
Bert Posted June 9, 2009 Posted June 9, 2009 The Vollatran project My blog: http://www.vollysinterestingshit.com/
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