Jump to content

Arrays GRRRR


Recommended Posts

Hi,

I am trying to rewrite the StringSplit function.

I just got to start and the idea of how to do it is in my head but first i need to get around with that array shit.

THis is my code up to now

#include <array.au3>

$split = _StringSplit( "xweg" , "x" )

If not @error Then MsgBox(0, "" , $split[1] )

Func _StringSplit( $s_string , $s_delimiters, $s_flag = 0 )
    Local $array = _ArrayCreate( $s_string )
    If not IsString( $s_string ) Then 
        SetError(1) ; no string to split
    ElseIf not IsString( $s_delimiters ) Then
        SetError(2) ; delimiter is no string
    ElseIf not IsString( $s_string ) and not IsString( $s_delimiters ) Then
        SetError(3) ; delimiter and $s_string are not strings
    ElseIf IsString( $s_string ) and IsString( $s_delimiters ) and _bigger( $s_string , $s_delimiters ) = 1 Then
        Local $len = StringLen( $s_string )
        Local $array = $s_string
        If StringInStr( $s_string , $s_delimiters ) Then
            For $a = 1 to $len
                ;this will be done when i get thos fucking arrays working ...
            Next
        Else
            Return $array
        EndIf
    ElseIf _bigger( $s_string , $s_delimiters ) = 0 Then
        SetError(4) ; delimiters longer than string to be splitted
    EndIf
EndFunc

Func _bigger( $s_first , $s_sec )
    $len1 = StringLen( $s_first )
    $len2 = StringLen( $s_sec )
    Select
        Case $len1 > $len2 
            Return 1
        Case $len1 < $len2 
            Return 0
        Case $len1 = $len2 
            Return 2
    EndSelect
EndFunc

If i run this in scite with newest Beta i get this error:

>"C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /beta /ErrorStdOut /in "C:\Dokumente und Einstellungen\Schnubby\Desktop\_stringsplit.au3" /autoit3dir "C:\Programme\AutoIt3\beta" /UserParams  
>Running AU3Check (1.54.1.1)  params:  from:C:\Programme\AutoIt3\beta
+>AU3Check ended.rc:0
>Running:(3.1.1.123):C:\Programme\AutoIt3\beta\autoit3.exe "C:\Dokumente und Einstellungen\Schnubby\Desktop\_stringsplit.au3"   
C:\Dokumente und Einstellungen\Schnubby\Desktop\_stringsplit.au3 (16) : ==> Subscript used with non-Array variable.: 
If not @error Then MsgBox(0, "" , $split[1] ) 
If not @error Then MsgBox(0, "" , $split^ ERROR
!>AutoIT3.exe ended.rc:999
>Exit code: 999 Time: 0.616

Can you tell me how i can fix this problem , because this is the first time i create my own arrays...

And DONT give me any suggestions how to do the split pls :D i want to do it myself...

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

#include <array.au3>

$split = _StringSplit( "xweg" , "x" )
if IsArray($split) Then ConsoleWrite("IsArray" & @LF)
If not @error Then MsgBox(0, "" , $split[0] )

Func _StringSplit( $s_string , $s_delimiters, $s_flag = 0 )
    Local $array = _ArrayCreate( $s_string )
    If not IsString( $s_string ) Then 
         ConsoleWrite(1 & @LF)
        SetError(1) ; no string to split
    ElseIf not IsString( $s_delimiters ) Then
         ConsoleWrite(2 & @LF)
        SetError(2) ; delimiter is no string
    ElseIf not IsString( $s_string ) and not IsString( $s_delimiters ) Then
         ConsoleWrite(3 & @LF)
        SetError(3) ; delimiter and $s_string are not strings
    ElseIf IsString( $s_string ) and IsString( $s_delimiters ) and _bigger( $s_string , $s_delimiters ) = 1 Then
        Local $len = StringLen( $s_string )
;~         Local $array = $s_string
        If StringInStr( $s_string , $s_delimiters ) Then
            For $a = 1 to $len
                ;this will be done when i get thos fucking arrays working ...
            Next
        Else
;~             Return $array
        EndIf
    ElseIf _bigger( $s_string , $s_delimiters ) = 0 Then
         ConsoleWrite(4 & @LF)
        SetError(4) ; delimiters longer than string to be splitted
    EndIf
            Return $array
EndFunc

Func _bigger( $s_first , $s_sec )
    $len1 = StringLen( $s_first )
    $len2 = StringLen( $s_sec )
    Select
        Case $len1 > $len2 
            Return 1
        Case $len1 < $len2 
            Return 0
        Case $len1 = $len2 
            Return 2
    EndSelect
EndFunc

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Ok and how do i return the array / arrays then?+#

€: ahhh i see it thanks :D

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

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