Using a "For...In...Next" loop

  • Hey,
    weiss einer wie das geht?

    [autoit]

    ; ##### Exercise 3 - Loops - Question 2 #####; Using a "For...In...Next" loop, run through each item in the Array provided and count the number of words that contain the letter "s".; --------------------------------------------------
    ; Text extract from: http://en.wikipedia.org/wiki/Singapore

    [/autoit][autoit][/autoit][autoit]

    Dim $text = "Singapore , officially the Republic of Singapore, is a southeast Asian city-state off the southern tip of the Malay Peninsula, 137 kilometres (85 mi) north of the equator. An island country made up of 63 islands, it is separated from Malaysia by the Straits of Johor to its north and from Indonesia's Riau Islands by the Singapore Strait to its south. The country is highly urbanised with very little primary rainforest remaining, although more land is being created for development through land reclamation."Dim $array = StringSplit($text," ")

    [/autoit]


    meine Idee war:

    [autoit]

    $with = IsString(9)

    [/autoit][autoit][/autoit][autoit]

    For $element In $array $with = $with & $element & @CRLFNext
    MsgBox(0, "For..IN Arraytest", "Result is: " & @CRLF & $with)

    [/autoit]

    funktioniert aber gar nichts...

    danke :)

  • Was erwartest du denn von IsString? Was sagt denn das "Is" aus?
    Vielleicht ob der Parameter ein String ist? Also bekommst du ein Bool zurück.

  • [autoit]

    Dim $text = "Singapore , officially the Republic of Singapore, is a southeast Asian city-state off the southern tip of the Malay Peninsula, 137 kilometres (85 mi) north of the equator. An island country made up of 63 islands, it is separated from Malaysia by the Straits of Johor to its north and from Indonesia's Riau Islands by the Singapore Strait to its south. The country is highly urbanised with very little primary rainforest remaining, although more land is being created for development through land reclamation.
    "Dim $array = StringSplit($text," ")Dim $count = 0
    For $element In $array $result = StringInStr($element, "s") If $result >0 Then $count = $count +1EndIfNextMsgBox(0, "Search result:", $count)

    [/autoit]


    ich habe mir das jetzt so gedacht. :)

  • Hi,

    hab ich auch so:

    Spoiler anzeigen
    [autoit]

    Dim $text = "Singapore , officially the Republic of Singapore, is a southeast Asian city-state off the southern tip of the Malay Peninsula, 137 kilometres (85 mi) north of the equator. An island country made up of 63 islands, it is separated from Malaysia by the Straits of Johor to its north and from Indonesia's Riau Islands by the Singapore Strait to its south. The country is highly urbanised with very little primary rainforest remaining, although more land is being created for development through land reclamation."
    Dim $aArray = StringSplit($text," "), $cnt = 0

    [/autoit] [autoit][/autoit] [autoit]

    For $element In $aArray
    if StringInStr($element,"s") Then $cnt += 1
    Next

    [/autoit] [autoit][/autoit] [autoit]

    MsgBox(0,"S",$cnt)

    [/autoit]

    Btw: kommt 26 raus? :P

    Gruß
    x0r

    Simon nörgelt, Simon nervt - aber Simon verbessert die Welt. Glaubt er.