Jump to content

Udf('s) : _sleep() ; _searchinstring() ; _chargetcount() ; _stringright() ; _stringleft() ; _removechar()


Busti
 Share

Recommended Posts

Ok First of all i know, some of this UDF's already exist's , about StringLen = GetCharCount, but mine is a other XD

ok letz go !

First of all you need this 2 Includes :

#include <String.au3>
#include <Misc.au3>

_Sleep( $TimeToSleep , $AbortKey )

Func _Sleep( $TimeToSleep , $HexSleepAbortKey="" )
$Sleep_Start = TimerStart()
Local $Diff = Round(TimerDiff($Sleep_Start)/1000)
While $Diff <= ($TimeToSleep)
 $Diff = Round(TimerDiff($Sleep_Start)/1000)
 If _IsPressed( $HexSleepAbortKey ) = 1 Then ExitLoop
WEnd
EndFunc

Example :

MsgBox( 0,"","timerstartet" )
$test = TimerStart()
_Sleep( 5 )
MsgBox( 0,"","timerdone : "&TimerDiff($test) )
Exit

_SearchInString( $S_SearchString )

Func _SearchInString($s_String, $s_SearchString)
    Dim $SearchArray[ _GetCharCount($s_String) ]
    Dim $StringSplit = _SplitString($s_String)
    Dim $FoundAt = "Found : [0]"&@CRLF&"Count : [NotFound]"&@CRLF&"Wort_Searched :  "&$s_SearchString
    For $i = 1 To $StringSplit[0]
        If $StringSplit[$i] = $s_SearchString Then $FoundAt = "Found :  [1]"&@CRLF&"Count : ["&$i&"]"&@CRLF&"Wort Searched :    "&$s_SearchString
        If $StringSplit[$i] = $s_SearchString Then Return $FoundAt
    Next
    Return $FoundAt
EndFunc ;==>_SearchInString

Example :

MsgBox(0,"",_SearchInString("Hi im cool", "cool"))

_GetCharCount($s_Word [,$Method=1]) && _RemoveChar( $String, $Count [, $Method = 1])

; MEthod 3 @ GetCharCount wont work yet !

Func _CharGetCount($s_Word,$Method=1)
    Local $Searched=0,$i,$Remove,$len,$SaveRemoveCount=0
    If $Method = 2 Then $s_Word = StringRegExpReplace( $s_Word, " " , "" )
    If $Method = 3 Then
        $len = StringInStr( $s_Word , "." )
        If $len Then
            For $i = 0 To StringLen( $s_Word )
                If $Searched = 1 Then ExitLoop
                    If _StringRight( $s_Word ,  $i ) = "." Then
                        Local $SaveRemoveCount = $i
                        $Searched = 1 
                        ExitLoop
                    EndIf
            Next
        EndIf
        For $Remove = 0 To $SaveRemoveCount 
            $s_Word = _RemoveChar( $s_Word , $len )
        Next
    EndIf
    Return StringLen( $s_Word )
EndFunc

Func _RemoveChar( $String , $Count=0 , $Method = 1)

Local $left
If $Method = 1 Then; remove 1 letter
If StringLen( $String ) < $Count Or $Count = 0 Then Return -1
 $String  = String( $String )
 $SaveString = StringLeft( $String , $Count-1 )
 Return $SaveString & StringTrimLeft( $String , $Count )
ElseIf $Method = 2 Then; remove spaces ^^
If StringLen( $String ) < $Count Or $Count = 0 Then Return -1
 Return StringRegExpReplace( $String , " " , "" )
EndIf

EndFunc

Example :

MsgBox( 0,"",_CharGetCount("hallo ich heisse lol.de",1))

_StringRight($Count) && _StringLeft($count)

; _StringRight needs 
; #include <string.au3>
Func _StringRight($s_Word, $i_Count)
; if you make _StringRight( "lol" , 2 ) he will return o and not ol
; same for _StringLeft
    $s_Word = _StringReverse($s_Word)
    $s_Split = StringSplit($s_Word, "")
    Return $s_Split;[$i_Count]
EndFunc ;==>_StringRight


Func _StringLeft($s_Word, $i_Count)
    $s_Split = StringSplit($s_Word, "")
    Return $s_Split;[$i_Count]
EndFunc ;==>_StringLeft

Example !

#include <string.au3>
$String = "HERE IS A (.) DOT!"
For $i = 0 to Stringlen( $string )

if _StringRight( $String ) = "." then msgbox( 0,"OMG","found a dot (.) ! Count :" & $i )
if StringRight( $String ) = "." then msgbox( 0,"OMG","found a dot (.) ! Count :" & $i )

next

hope ya like them :)

Edited 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

  • Moderators

Awesome that your already putting stuff in scripts and scraps, I was here almost a year before I started.

Just some comments:

Your sleep method:

Func _Sleep( $TimeToSleep , $HexSleepAbortKey="" )
$Sleep_Start = TimerStart()
Local $Diff = Round(TimerDiff($Sleep_Start)/1000)
While $Diff <= ($TimeToSleep)
$Diff = Round(TimerDiff($Sleep_Start)/1000)
If _IsPressed( $HexSleepAbortKey ) = 1 Then ExitLoop
WEnd
EndFunc
Could use some actual "Sleep" in there so your not burning up the CPU.

So instead of using _IsPressed() you could use a HotKeySet()

Global $i_CheckState = 0

Func _Sleep($i_TimeToSleep, $v_HotKeyAbort = "{Esc}")
    HotKeySet($v_HotKeyAbort, "EndSleep")
    Local $i_Timer = TimerInit()
    While $i_CheckState = 0
        Sleep(10)
        If TimerDiff($i_Timer) >= $i_TimeToSleep Then ExitLoop
    Wend
    $i_CheckState = 0
EndFunc

Func EndSleep()
    $i_CheckState = 1
EndFunc
The only issue is Having to have the Global Outside the Functions... but easy enough to deal with :o

The others I hadn't looked at much, but good job!!

Edit: Brain Fart :)

Edit2: Double Brain Fart!! :mellow::)

Edited by SmOke_N

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

  • Moderators

it wont eat your CPU, becouse theyre is an If in it^^

You're a tad mistaken there on the CPU usage.

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

  • Moderators

put sleep(100) and evry thing is fine, but i like my sleep, becouse i can abort it :)

I was complimenting you... if you try my edited version from earlier.. you can abort it. IMHO it's cleaner... you say you don't want to use the Global outside var, but then you have to use an #include <Misc.au3> so really it's six of one and one half dozen of the other... I wasn't putting your code down, just offering another solution.

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

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