Jump to content

Array Help


Recommended Posts

Hi guys

I am a newbie

I want help with the sorting of arrays. IT wont let me sort with the names with numbers in front of it.

I have a data of:

age and name i want to delete the double entries and sort by name

the data is :

24 steve smith

24 john gibbons

18 Chris henry

22 George Clooney

24 George Clooney

29 John gibbons

24 john hobart

And the output i wanted is:

George Clooney - 22, 24

john gibbons - 24, 29

john hobart - 24

Steve Smith - 24

Can someone please help.

Thanks

Harpreet

Link to comment
Share on other sites

  • Moderators

Hi guys

I am a newbie

I want help with the sorting of arrays. IT wont let me sort with the names with numbers in front of it.

I have a data of:

age and name i want to delete the double entries and sort by name

the data is :

24 steve smith

24 john gibbons

18 Chris henry

22 George Clooney

24 George Clooney

29 John gibbons

24 john hobart

And the output i wanted is:

George Clooney - 22, 24

john gibbons - 24, 29

john hobart - 24

Steve Smith - 24

Can someone please help.

Thanks

Harpreet

At the cost of sounding arrogant, it seems you want us to write it for you... care to share with us what exactly you've done to do what it is you are wanting done?

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

At the cost of sounding arrogant, it seems you want us to write it for you... care to share with us what exactly you've done to do what it is you are wanting done?

I am not asking you to write for me all I want is to know the way i can sort with names though there are numbers in front. I can delete the duplicate entries i am not able to sort it the way I want.
Link to comment
Share on other sites

move 3 first characters from each field from left to right side (stringtrimleft etc.). Next make an loop with will check all field of array (excluding 3 lat characters) of being repeted in array(ArraySearch), if found something copy the 3 last character to the search field (you may add some , or other delimeter), delete the founded doubled field (ArrayDelete) and do it until you will receive 0 (no doubled string finded), and do it on whole array. On the end Use ArraySort to sort the array :) If that what you wanted from us ?

Edited by Uriziel01
Link to comment
Share on other sites

Here is the code i am writing

#include <GUIConstants.au3>

#include <Array.au3>

GUICreate("My GUI") ; will create a dialog box that when displayed is centered

GUISetState (@SW_SHOW) ; will display an empty dialog box

$Text_box = GUICtrlCreateEdit("Text Area",10,10,350,350,$ES_AUTOVSCROLL+$WS_VSCROLL)

$convert = GUICtrlCreateButton("Convert",150,360,70,20)

;~ 15 george St

;~ 20 flinder av

func Convert()

;~ $a = 1

Dim $avArray[1]

Dim $avArray_num [1]

;~ Dim $arGrid[2][4] = [$avArray,$avArray_num]

;~ Dim $arGrid[$avArray[]][$avArray_num[]]

$text = GUICtrlRead($Text_box)

$text = StringStripWS($text,2)

;~ MsgBox(0,"",$text)

Do

;~

$result = StringInStr($text, @CRLF)

;~ MsgBox(0,"",$result)

If $result <> 0 Then

$result = $result + 1

ElseIf $text <> "" Then

$text = StringReplace($text, @TAB, "|")

;~ _ArrayAdd( $avArray,$text)

ExitLoop

EndIf

$First = StringLeft($text,$result)

$text = StringTrimLeft($text,$result)

$text = StringStripWS($text,2)

$First = StringStripWS($First,2)

$First = StringReplace($First, @TAB, "|")

;~ MsgBox(0, "", $First)

$num_pos = StringInStr($First, "|")

$number = StringLeft($First,$num_pos)

$number = StringTrimRight($number,1)

$street = StringTrimLeft($First,$num_pos)

_ArrayAdd( $avArray,$street)

_ArrayAdd( $avArray_num,$number)

until $result = 0

;~ _ArrayDisplay($arGrid, "_ArrayDisplay() 2D Test", 1, 1)

;~ _ArrayDisplay( $arGrid, "Updated Array" )

;~ _ArrayToString ( $avArray, " ")

;~ _ArraySort($avArray,0)

_ArrayDisplay( $avArray, "UnSorted" )

_ArrayDisplay( $avArray_num, "Sorted" )

_ArraySort($avArray)

_ArrayDisplay( $avArray, "Sorted" )

;~ Do

;~ $spc = StringMid($text, $a , 1)

;~ $space = StringIsSpace($spc)

;~ $a = $a + 1

;~ $power = $power & $spc

;~ Until $space = 1

;~ $power = StringStripWS($power,2)

;~ MsgBox(0, "", $power)

EndFunc

;~ Func Array()

;~ Dim $avArray[]

;~ for $array to

;~ $result = StringInStr($text, @CRLF)

;~ For $i = 0 to $result=0 Step +1

;~ MsgBox(0, "Count down!", $i)

;~ Next

;~ EndFunc

;~ MsgBox(0,"",$text)

; Run the GUI until the dialog is closed

While 1

$msg = GUIGetMsg()

Select

Case $msg = $convert

Convert()

case $msg = $GUI_EVENT_CLOSE

Exit

EndSelect

Wend

Link to comment
Share on other sites

move 3 first characters from each field from left to right side (stringtrimleft etc.). Next make an loop with will check all field of array (excluding 3 lat characters) of being repeted in array(ArraySearch), if found something copy the 3 last character to the search field (you may add some , or other delimeter), delete the founded field (ArrayDelete) and do it until you will receive 0 (no doubled string finded), and do it on whole array. On the end Use ArraySort to sort the array :) If that what you wanted from us ?

Thanks Mate i will try that

Cheers

Link to comment
Share on other sites

But you must now that when it will be an large array witch 800+ elements this may be really slooooooooow, and then we will must find some other way :) Good luck !

I dont think it will be more than that yet.

BUt will think on that once its over it.

Thanks alot for your help.

i am gonna try that.

Link to comment
Share on other sites

  • Moderators

#include <array.au3>
$sText = "24 steve smith" & @CRLF & _
            "24 john gibbons" & @CRLF & _
            "18 Chris henry" & @CRLF & _
            "22 George Clooney" & @CRLF & _
            "24 George Clooney" & @CRLF & _
            "29 John gibbons" & @CRLF & _
            "24 john hobart"

$a = StringSplit(StringStripCR($sText), @LF)

_myArrayConvert($a)

_ArrayDisplay($a)

Func _myArrayConvert(ByRef $avArray, $iBase = 1)
    Local $aTemp = $avArray, $iCC
    For $iCC = $iBase To UBound($aTemp) - 1
        $aTemp[$iCC] = StringRegExpReplace($aTemp[$iCC], "^\d+\s*", "")
    Next
    _ArrayUnique($aTemp, "", $iBase, 0)
    _ArraySort($aTemp)
    Local $aReturn[UBound($aTemp)]
    Local $aSRE, $sTemp, $nCC, $sTempFound, $bFound
    For $iCC = $iBase To UBound($aTemp) - 1
        $sTempFound = $aTemp[$iCC]
        For $nCC = $iBase To UBound($avArray) - 1
            If StringRegExp($avArray[$nCC], "(?i)\d+\s*" & $sTempFound & "$") Then
                If StringInStr($aTemp[$iCC], " - ") = 0 Then
                    $aTemp[$iCC] = $aTemp[$iCC] & " - " & StringRegExpReplace($avArray[$nCC], "(\s\w+\s\w+)", "")
                Else
                    $aTemp[$iCC] = $aTemp[$iCC] & ", " & StringRegExpReplace($avArray[$nCC], "(\s\w+\s\w+)", "")
                EndIf
            EndIf
        Next
    Next
    $avArray = $aTemp
    Return
EndFunc

Func _ArrayUnique(ByRef $aArray, $vDelim = '', $iBase = 1, $iCase = 1)
    If Not IsArray($aArray) Then Return SetError(1, 0, 0)
    If $vDelim = '' Then $vDelim = Chr(01)
    Local $sHold
    For $iCC = $iBase To UBound($aArray) - 1
        If Not StringInStr($vDelim & $sHold, $vDelim & $aArray[$iCC] & $vDelim, $iCase) Then _
            $sHold &= $aArray[$iCC] & $vDelim
    Next
    If $sHold And $iBase = 1 Then
        $aArray = StringSplit(StringTrimRight($sHold, StringLen($vDelim)), $vDelim)
        Return SetError(0, 0, 0)
    ElseIf $sHold And $iBase = 0 Then
        Local $avArray = StringSplit(StringTrimRight($sHold, StringLen($vDelim)), $vDelim)
        ReDim $aArray[UBound($avArray) - 1]
        For $iCC = 1 To UBound($avArray) - 1
            $aArray[$iCC - 1] = $avArray[$iCC]
        Next
        Return SetError(0, 0, 0)
    EndIf
    Return SetError(2, 0, 0)
EndFunc
Edit:

Forgot to sort the array :)

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

Thanks Alot...

I thought you are not gonna help when i had your first answer and then i started working on what the other guy told me...

Though my coding is not as good as yours.. But is working now.

But thankyou once again for all your help..

You code is lot better than me..

Cheers mate..

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