Jump to content

StringReverse Rewriting :)


Recommended Posts

Hi,

I want to rewrite _StringReverse but it returns this "" and not the reversed string. This is my code so far

#include <String.au3>
Msgbox(0,'',_StringReverse( "esreveR" ) &  @CRLF & StringReverse("esreveR"))
Exit

Func StringReverse( $s_string )
    Local $string = ""
    Local $chars
    For $a = 1 to 255
        $chars = $chars & "|" & Chr( $a )
    Next
    Local $split = StringSplit( $s_string , $chars )
    For $b =  $split[0] to 1 Step -1
        $string = $string & $split[$b]
    Next
    Return $string
EndFunc

I think it stucks at the second for loop but i dunno why ...

Regards

--------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote]

Link to comment
Share on other sites

I want to rewrite it to learn it and i already thought of stringmid but when i walked home from bus i got this idea with stringsplit and i dont know why it does not work...

€: its done with wOuters Help :D

Func StringReverse( $s_string ) 
    Local $string
    Local $split = StringSplit( $s_string , '' ) 
    
    For $b = $split[0] to 1 Step -1 
        $string &= $split[$b] 
    Next 
    Return $string 
EndFunc
Edited by Daniel W.

--------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote]

Link to comment
Share on other sites

I want to rewrite it to learn it and i already thought of stringmid but when i walked home from bus i got this idea with stringsplit and i dont know why it does not work...

: its done with wOuters Help :D

Func StringReverse( $s_string ) 
    Local $string
    Local $split = StringSplit( $s_string , '' ) 
    
    For $b = $split[0] to 1 Step -1 
        $string &= $split[$b] 
    Next 
    Return $string 
EndFunc
That's the second :D hehe
Link to comment
Share on other sites

my best attempt:

Using ''
_StringReverse: 1 - 759.462608774554
xStringReverse: 1 - 916.683793213463
Using 'R'
_StringReverse: 0 - 1188.24971622757
xStringReverse: 0 - 862.55897285795
Using 'AutoIt v3'
_StringReverse: 0 - 3706.05057500871
xStringReverse: 0 - 2915.81731524058

#include <String.au3>

Func xStringReverse($s_string)
    Local $v_temp = StringLen($s_string)
    If $v_temp > 1 Then
        $v_temp = ''
        Local $as_split = StringSplit($s_string, '')
        For $i = $as_split[0] To 1 Step - 1
            $v_temp &= $as_split[$i]
        Next
        Return $v_temp
    Else
        SetError(BitXOR($v_temp, 1))
        Return $s_string
    EndIf
EndFunc   ;==>xStringReverse

$c = 10000

ConsoleWrite('Using ''''' & @LF)

$t = TimerInit()
For $i = 0 To $c
    _StringReverse("")
Next
ConsoleWrite("_StringReverse: " & @error & ' - ' & TimerDiff($t) & @LF)

$t = TimerInit()
For $i = 0 To $c
    xStringReverse("")
Next
ConsoleWrite("xStringReverse: " & @error & ' - ' & TimerDiff($t) & @LF)

ConsoleWrite('Using ''R''' & @LF)

$t = TimerInit()
For $i = 0 To $c
    _StringReverse("R")
Next
ConsoleWrite("_StringReverse: " & @error & ' - ' & TimerDiff($t) & @LF)

$t = TimerInit()
For $i = 0 To $c
    xStringReverse("R")
Next
ConsoleWrite("xStringReverse: " & @error & ' - ' & TimerDiff($t) & @LF)

ConsoleWrite('Using ''AutoIt v3''' & @LF)

$t = TimerInit()
For $i = 0 To $c
    _StringReverse("AutoIt v3")
Next
ConsoleWrite("_StringReverse: " & @error & ' - ' & TimerDiff($t) & @LF)

$t = TimerInit()
For $i = 0 To $c
    xStringReverse("AutoIt v3")
Next
ConsoleWrite("xStringReverse: " & @error & ' - ' & TimerDiff($t) & @LF)
Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

could you check myne too ?

Func _StringReverse($_String)
    Local $Ret
    If StringLen($_String) < 1 Then Return ""
    For $i = 1 To StringLen($_String)
        $Ret &= StringRight(StringTrimRight($_String,$i-1),1)
    Next
    Return $Ret
EndFunc
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

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