Jump to content

Need some help...


Recommended Posts

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
EndFunc

As 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? :D

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.

Link to comment
Share on other sites

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)

NEWHeader1.png

Link to comment
Share on other sites

Ah, fixed it.

A little test:

$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 :D

Edited 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.

Link to comment
Share on other sites

Ok, I didn't say anything the first time... but

If $sSplit[$i] = $sSplit[$i] Then

what the hell is that?? :D

8)

Well, after some thinking, if $sSplit[1] = the first splitted char... Etc.

I had some trouble finding it out... But it works :D

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...