Jump to content
sree161

how to sperate odd and even parts of array ???

Recommended Posts

sree161

Hi,
i have read a note pad and separated data in it using one seperater. i output is in array $s[1], $s[2], $s[3], $s[4], $s[5]....$s[12].
i want to send anyone of odd or even arrays to new notepad. can someone suggest some logic???
i am done till below code

Quote

$filePath = "C:\Users\ant\Desktop\afdsf.txt"

Local $Input2 = FileRead($filePath)
MsgBox(0,'input2',$Input2)
$s = StringSplit($Input2 & "iretation" & @CRLF ,"iretation" & @CRLF, 1) ; $STR_ENTIRESPLIT (1) = entire delimiter string is needed to mark the split

$iLRI = UBound($s) - 2 ; Last Array Index
MsgBox(0,'iLRI',$iLRI)

Local $sDisplay = "Output;" & @CRLF
For $i = 1 To $s[0] Step 1

    $sDisplay = "$s[" & $i & "]: " & $s[$i] & @CRLF
    MsgBox(0, "Results", $sDisplay)

 Next

 

Edited by sree161
simply

Share this post


Link to post
Share on other sites
water
If Mod($i, 2) = 0 Then
    ; process all even records here
Else
    ; process all odd records here
EndIf

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
czardas

You can also use:

For $i = 0 To Ubound($aArray) -1 Step 2 ; to process even elements: for odd elements start with $i = 1.

You can also create two arrays using regular expressions. I'd have to double check the syntax. I think the suggestions made already are adequate.

Edited by czardas

Share this post


Link to post
Share on other sites
Malkey

An example.

Opt("WinTitleMatchMode", -2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

Local $Even
Local $filePath = "C:\Users\ant\Desktop\afdsf.txt" ; "Gui.txt" ;
Local $iretation = "" ; "iretation" ;
Local $Input2 = FileRead($filePath)
MsgBox(0, 'input2', $Input2)

Local $a = StringSplit(StringStripCR($Input2), $iretation & @LF, 1) ; $STR_ENTIRESPLIT (1) = entire delimiter string is needed to mark the split

While Sleep(100)
    $Even = InputBox("Testing", "Enter 1 for even, or" & @CRLF & "        0 for not even.", "", " M1")
    If @error Then Exit ; Cancel or top-right exit button pressed
    If $Even = "0" Or $Even = "1" Then
        ExitLoop
    Else
        MsgBox(0, "Error", 'Enter either a "1", or a "0" only', 2)
    EndIf
WEnd

Run("notepad.exe")
WinWaitActive("Notepad")
For $i = (1 + $Even) To UBound($a) - 1 Step 2
    Send($a[$i] & @LF)
Next

 

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

×