Jump to content

Recommended Posts

Posted

Hi Im using the below to count the number of times "o" repeats in my $string "olololololol" etc

Now then I get the position of each one of those o's.

But how do I store the positions into an array??

Func _StringCount($String, $SubString)
    return (StringLen($String) - StringLen(StringReplace($String, $SubString, ""))) / StringLen($SubString)

EndFunc

$String = "olololololololol"
$SubString = "o"
MsgBox(0,"" ,  _StringCount($String, $SubString))

Local $i
Local $tol = 100

For $i = 1 To 100 Step +1

    Local $result = StringInStr($String, $SubString, 0, $i)
        if $result == 0 Then
            Exit
        Else
            MsgBox(0,"DEMO1", $result)
        EndIf

Next
Posted

You need the number of "o" in your string or the position of each "o"?

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

  On 5/7/2013 at 11:43 AM, 'water said:

You need the number of "o" in your string or the position of each "o"?

Well they dont have to be in the same array.

So

1 array contains the number of o's

another contains the position of each of those o's

:)

Posted

Example script:

#include <array.au3>
$sString = "olololololol"
$sSearch = "o"
StringReplace($sString, $sSearch, "") ; @extended is set to the number of replacements
Global $aPositions[@extended + 1] = [@extended]
Global $iPos
For $i = 1 To 99999
    $iPos = StringInStr($sString, $sSearch, Default, $i)
    If $iPos = 0 Then exitloop
    $aPositions[$i] = $iPos
Next
_ArrayDisplay($aPositions)
exit

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

Glad to be of service :D

My UDFs and Tutorials:

  Reveal hidden contents

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...