Jump to content

Store values into an array?


Recommended Posts

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
Link to comment
Share on other sites

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

:)

Link to comment
Share on other sites

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:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Glad to be of service :D

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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