Jump to content
Sign in to follow this  
olo

Store values into an array?

Recommended Posts

olo

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

Share this post


Link to post
Share on other sites
water

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


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
olo

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

:)

Share this post


Link to post
Share on other sites
water

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
  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
olo

wow thanks that works perfect!

Share this post


Link to post
Share on other sites
water

Glad to be of service :D


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
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
Sign in to follow this  

×