Sign in to follow this  
Followers 0
flaxcrack

_StringKeep() :: My Very First UDF

9 posts in this topic

Here is my very first UDF. Go easy on me!

#comments-start
Function Name:  _StringKeep()
Description:      Designed to perform the opposite of StringTrimLeft/Right
Parameter(s):    $nLen - Is how much of the variable you wish to keep
                  $nVar - Is the variable that be used
                  $nOpt - Is the Option that can be used:
                    1 - Default Option - Will keep the length assigned from the right
                    2 - -------------- - Will keep the length assigned from the left
Requirement(s):   AutoIt3 Beta
Return Value(s):  On Success - The variable with the assigned length to keep
                  On Failure - sets @ERROR = 1
Author:     Flaxcrack @ www.autoitscript.com

Example:          $in = "Here is my input into the script.  Look at me go"
                  $out = _FixedVar(16, $in)
                  _SringKeep() will return: Here is my input 

#comments-end

Func _StringKeep($nLen, $nVar, $nOpt = 1)
    Local $nW1
    Local $nW2

    If $nOpt = 1 Then
        $nW1 = 1
    EndIf

    If $nOpt = 2 Then
        $nW2 = 1
    EndIf

    If Not $nOpt = 0 Or 2 Then
        SetError(1)
    EndIf

    While $nW1 = 1
        $nVar = StringTrimRight($nVar, StringLen($nVar) - $nLen)
        Return $nVar
        $nw1 = $nw1 + 1
    WEnd

    While $nW2 = 1
        $nVar = StringTrimLeft($nVar, StringLen($nVar) - $nLen)
        Return $nVar
        $nw2 = $nw2 + 1
    WEnd

EndFunc

[quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD()

Share this post


Link to post
Share on other sites



Here is my very first UDF. Go easy on me!

Function Name: _StringKeep()

Description: Designed to perform the opposite of StringTrimLeft/Right

:lmao: Is this similar to StringLeft() and StringRight() ?


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

;) Is this similar to StringLeft() and StringRight() ?

:lmao: I made something that was already there. Well that sucks, but I guess the bright side is that you can accomplish StringLeft() and StringRight() with less key strokes using StringKeep(). o:)

[quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD()

Share this post


Link to post
Share on other sites

:lmao: I made something that was already there. Well that sucks, but I guess the bright side is that you can accomplish StringLeft() and StringRight() with less key strokes using StringKeep(). o:)

You know what's so about the HelpFile ? it has this nice section for all functions:

Related

String, StringInStr, StringLeft, StringLen, StringLower, StringMid, StringRight, StringTrimRight, StringUpper

;)


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

You know what's so about the HelpFile ? it has this nice section for all functions:

;)

I know. I consulted the all mighty help file after your first post. And I was thinking to my self that I was being rather clever. :lmao:


[quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD()

Share this post


Link to post
Share on other sites

I know. I consulted the all mighty help file after your first post. And I was thinking to my self that I was being rather clever. :lmao:

what not so clever is the logic of this sequence:

While $nW1 = 1
        $nVar = StringTrimRight($nVar, StringLen($nVar) - $nLen)
        Return $nVar
        $nw1 = $nw1 + 1
    WEnd

$nw1 can never be incremented if you need it. Samething is true for the next sequence with $nw2.

;)

Share this post


Link to post
Share on other sites

what not so clever is the logic of this sequence:

While $nW1 = 1
        $nVar = StringTrimRight($nVar, StringLen($nVar) - $nLen)
        Return $nVar
        $nw1 = $nw1 + 1
    WEnd

$nw1 can never be incremented if you need it. Samething is true for the next sequence with $nw2.

:lmao:

@JMP Can you please explain what you mean?

[quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD()

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

@JMP Can you please explain what you mean?

Come on.... think about it ...one line at the time.

While $nW1 = 1 ; <== what is the need of the endless loop ?

$nVar = StringTrimRight($nVar, StringLen($nVar) - $nLen) ; Ceate the result value

Return $nVar ; Return back to the line that called this function

$nw1 = $nw1 + 1 ; <= This line will NEVER be reached

WEnd ; <== what is the need on the endless loop ?

so this code does the same as your UDF :

Func _StringKeep($nLen, $nVar, $nOpt = 1)
    If $nOpt = 1 Then Return StringTrimRight($nVar, StringLen($nVar) - $nLen)
    If $nOpt = 2 Then Return StringTrimLeft($nVar, StringLen($nVar) - $nLen)
    SetError(1)
EndFunc

:lmao:

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Come on.... think about it ...one line at the time.

While $nW1 = 1 ; <== what is the need of the endless loop ?

$nVar = StringTrimRight($nVar, StringLen($nVar) - $nLen) ; Ceate the result value

Return $nVar ; Return back to the line that called this function

$nw1 = $nw1 + 1 ; <= This line will NEVER be reached

WEnd ; <== what is the need on the endless loop ?

so this code does the same as your UDF :

Func _StringKeep($nLen, $nVar, $nOpt = 1)
    If $nOpt = 1 Then Return StringTrimRight($nVar, StringLen($nVar) - $nLen)
    If $nOpt = 2 Then Return StringTrimLeft($nVar, StringLen($nVar) - $nLen)
    SetError(1)
EndFunc

;)

See. Thats all I needed. A little explaining. I never said was an ueber programer. It is ofcourse my FIRST UDF. :lmao:


[quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD()

Share this post


Link to post
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
Sign in to follow this  
Followers 0