Jump to content
Sign in to follow this  
johnmcloud

Write different array(s) on the same file

Recommended Posts

johnmcloud

Hi guys,

I have 2 question ;)

First:

I have 2 array with _StringBetween

$aArrayTask = _StringBetween($result, 'align=left>', ' </td>')
$aArrayName = _StringBetween($result, '<td width=62% align=left>', '<td width=30% align=left>')

I write it on separate file using _FileWriteFromArray. But if want to write on the same txt like:

$aArrayName & " " & $aArrayTask

How to do that?

Second

One of the array have a little problem:

blaba
babadsda
sadasddsa
<font color=#0066FF>dsasdadsa
<font color=#0088FF>dsasadsd
reerre
rrtrtrt

I can remove the <font color=#0066FF> before i write on the file? Or i need to remove after? The font color name change everytime.

Thanks for support ;)

Share this post


Link to post
Share on other sites
water

Use function _ArrayConcatenate to concatenate the arrays.


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
johnmcloud

Hi water, i don't want to concatenate like this:

1
2
3
A
B
C

But like this:

1 A
2 B
3 C

Thanks

EDIT: About String replace, i have a problem:

With this work:

$read = "<font color=#66FFFF>Work with me"
$after = StringRegExpReplace($read, "([<])(.*)([>])", "")
ConsoleWrite($after)

But not with this:

$read = "<font color=#66FFFF> NOT Work with me <font color>"
$after = StringRegExpReplace($read, "([<])(.*)([>])", "")
ConsoleWrite($after)

I'm not an StringRegExpReplace expert, so what is the problem?

Edited by johnmcloud

Share this post


Link to post
Share on other sites
water

In this case you have to loop through the arrays and create an output array yourself.


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
johnmcloud

A little example? :D

Share this post


Link to post
Share on other sites
water

In pseudo code:

determine the dimension of both arrays

Make sure both arrays have the same number of rows (or you have to check in the loop)

Define a 2D array with this number of rows and 2 columns

loop for the number of entries in the input array

write entry of array 1 to cell 0 of the output array

write entry of array 2 to cell 1 of the output array

endloop

Good luck!


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
johnmcloud

I'll check it out later.

An easy task, what is wrong?

Global $ini = @WorkingDir & "test.txt"
$read = _INetGetSource([url="http://www.babbaab.com"]www.babbaab.com[/url])

FileOpen($ini, 1)
$aArrayFinal = _StringBetween($read, '<td width=62% align=left>', ' </td>')
$after = StringRegExpReplace($aArrayFinal, "([<])(.*)([>])", "")
_FileWriteFromArray($ini, $after)
FileClose($ini)

I see a blank file. But in this way work:

Global $ini = @WorkingDir & "test.txt"
$read = _INetGetSource([url="http://www.babbaab.com"]www.babbaab.com[/url])

FileOpen($ini, 1)
$aArrayFinal = _StringBetween($read, '<td width=62% align=left>', ' </td>')
$after = StringRegExpReplace($aArrayFinal, "([<])(.*)([>])", "")
_FileWriteFromArray($ini, $aArrayFinal)
FileClose($ini)

I'd like to avoid to do the StringRegExpReplace after i have make the file. How to do?

Thanks

Share this post


Link to post
Share on other sites
water

Does the StringRegExpReplace work for you? If yes, why replace with something else?


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
johnmcloud

Maybe i wasn't clear.

That's what i do now

1- Make array

2- Write array on file

3-StringRegExReplace on the file

4-Save the file, again.

But i'd like to remove the second point, so:

1- Make array

2- StringRegExReplace directly on the array

3- Save the result on the file

Share this post


Link to post
Share on other sites
water

You can't pass an array to StringRegExpReplace. Use _ArrayToString and @CRLF as a separator before using StringRegExpReplace. Then you can write the whole string to a file using FileWrite.


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
Robjong

Maybe I have not got this right but this might work...

; ... do the InetGet and StringBetween stuff ...

; example arrays, names and tasks
Global $aNames[5] = [4, 'A', 'B', 'C', '<font color=#0066FF>D']
Global $aTasks[4] = [3, '<font color=#0088FF>dsasadsd', 'reerre', 'rrtrtrt']

$sData = _KeyValueArraysToString($aNames, $aTasks)
; ... $sData is the list as string, you can write it to a file now ...
ConsoleWrite($sData)

Func _KeyValueArraysToString($aKeys, $aValues)
    Local $iKeys = UBound($aKeys), $iValues = UBound($aValues), $iUB = $iKeys
    If $iKeys < $iValues Then
        $iUB = $iValues
    EndIf

    Local $sString = '', $sKey, $sValue
    For $i = 1 To $iUB - 1 Step 1 ; loop through the array
        ; reset vars
        $sKey = ''
        $sValue = ''
        ; get key and value from arrays, make sure the index is not out of bounds
        If $i < $iKeys Then $sKey = $aKeys[$i]
        If $i < $iValues Then $sValue = $aValues[$i]
        ; add data to string
        $sString &= $sKey & ' ' & $sValue & @LF
    Next

    Return SetError(0, $i, StringRegExpReplace($sString, '<[^>]+>', '')) ; return string with tags removed
EndFunc   ;==>_KeyValueArraysToString

Share this post


Link to post
Share on other sites
johnmcloud

StringRegExpReplace($aArrayToString, '<[^>]+>', '')

Thanks this is what i need for now ;)

I'll check it out all the rest of the array stuff

Edited by johnmcloud

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  

  • Similar Content

    • rm4453
      By rm4453
      Hello,
       
      I am currently writing a program that parses a massive table from a website, and need a way to add a progress bar while parsing.
      I am currently using the function _IETableWriteToArray($oObj, True) to parse the array. I need the progress bar to update as the table is parsed, not just at the end of the parsing.
      Any help at all would be very much appreciated!
       
      *EDIT --> The array I am left with after parsing is $array[0-50000][16]
    • TrashBoat
      By TrashBoat
      So Im trying to make a simple 2d game and make some sort of collision detection so why not to make a 2 dimensional array but i have no clue how  to write it in multiple lines
      Global $map[5,5] = [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0] something like this but it doesn't work
    • Zein
      By Zein
      #include "..\Include\Array.au3" #include "..\Include\File.au3" #include "..\Include\AutoItConstants.au3" Local $aRetArray Local $sFilePath = "n.csv" _FileReadToArray($sFilePath, $aRetArray, ",") ; _FileReadToArray($sFilePath, $aRetArray, $FRTA_COUNT, ",") _ArrayDisplay($aRetArray, "Original", Default, 8) The above code shows two versions of _FileReadToArray and both don't work as expected.
      The first one doesn't use the comma as a delimiter. (so I get a single column array)  I tried adding "Default" between $aRetArray and "," then it told me it had an incorrect number of parameters. 

      I looked again at the documentation:
       
      #include <File.au3> _FileReadToArray ( $sFilePath, ByRef $vReturn [, $iFlags = $FRTA_COUNT [, $sDelimiter = ""]] )
      And I with or without the flags params I should be getting a 2D array due to my file being a csv. 
      I then tried a regular flag, $FRTA_COUNT, and it tells me that I'm using a variable $FRTA_COUNT while it's not declared. Tried putting in 1 instead and it told me again, incorrect number of params. 

       
    • ternal
      By ternal
      Hi,
      Recently I have had the need to do a sort and then do a second sort while the item of the first sort stays the same ( double sorting , first on column x then while column x is the same sort column y).
      I did not put much efffort into error checking but so far I did not need it.
      For my applications so far it works perfectly however if someone is willing I want to test this extensivly.
      If anyone has big lists of random stuff to sort could you try this out please?
      #include <Array.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ArraySort_Double ; Description ...: ; Syntax ........: _ArraySort_Double (Byref $array[, $first_index = Default[, $second_index = Default[, $ascending = Default]]]) ; Parameters ....: $array - 2d array to sort. ; $first_index - [optional] first column to sort. Default is 0. ; $second_index - [optional] second column to sort. Default is 1. ; $ascending - [optional] ascending/descending. Default is 1. ; Return values .: 1 if no errors occured , -1 if errors occured ; Author ........: Ternal ; Remarks .......: Needs excessive testing. ; Related .......: _arraysort() ; =============================================================================================================================== Func _ArraySort_Double (byref $array, $first_index = Default, $second_index = Default, $ascending = Default) Local $temp_value Local $counter = 1 If UBound($array, $UBOUND_DIMENSIONS) <> 2 Then MsgBox(0, "error", "error") return -1 EndIf If $first_index = Default Then $first_index = 0 If $second_index = Default Then $second_index = 1 If $ascending = Default Then $ascending = 1 _ArraySort($array, $ascending, 0, 0, $first_index); you can alter settings of primary sort here If @error Then MsgBox(0, "error", @error) return -1 EndIf $temp_value = $array[0][$first_index] For $x = 1 to UBound($array, 1) - 1 If Mod( $x, 10000) = 0 Then ConsoleWrite("at " & $x & " of a total : " & UBound($array, 1) & @CRLF) If $array[$x][$first_index] = $temp_value Then $counter+= 1 If $x = UBound($array, 1) - 1 Then; do last line here(if last line is not a new item) _ArraySort($array, $ascending, $x - $counter, $x, $second_index);you can alter settings of secondary sort here(don't forget to place line 34 the exact same) If @error Then MsgBox(0, "error", @error) return -1 EndIf EndIf Else If $counter > 0 Then ;at least 2 of the same _ArraySort($array, $ascending, $x - $counter, $x - 1, $second_index);you can alter settings of secondary sort here(don't forget to place line 29 the exact same) If @error Then MsgBox(0, "error", @error) return -1 EndIf $counter = 1 EndIf EndIf $temp_value = $array[$x][$first_index] Next Return 1 EndFunc Kind regards, Ternal
    • TrashBoat
      By TrashBoat
      So I've made this script that detects how long i have held down my left mouse button for and stores the information in an array and then sorts its using _ArraySort but the output is half sorted half broken.
      Here's my script:
      HotKeySet("{F1}","_exit") #include <Misc.au3> #include <Timers.au3> #include <Array.au3> Local $dll = DllOpen("user32.dll") $on = False Global $array[0] While(1) If _IsPressed(01,$dll) Then $timer = _Timer_Init() While _IsPressed(01,$dll) Sleep(1) WEnd $time = _Timer_Diff($timer) _ArrayAdd($array,"Time: " & Floor($time) & " ms") ;~ ConsoleWrite("Time: " & Floor($time) & " ms" & @CRLF) EndIf Sleep(50) WEnd Func _exit() _ArraySort($array) _ArrayDisplay($array) Exit EndFunc And the output:

      See how its not sorted?  What is the problem here?
×