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-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (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
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-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (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
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-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (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
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-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (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
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-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (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
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

    • Skeletor
      By Skeletor
      Hi Virtual People,
      My array works perfectly fine. However, what is the best practice if the line in the array doesn't have the correct amount of columns and if I can add a placeholder?

       
      For $count = 1 To _FileCountLines($FileRead1) Step 1 $string = FileReadLine($FileRead1, $count) $input = StringSplit($string, ",", 1) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value2, "A1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value1, "B1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value3, "C1") Next  
    • MrCheese
      By MrCheese
      hi all,
      reviewing the forum, this thread is applicable: 
       
       
      I wanted to know if there is now a better way to do this?
      In essence, I load a tab delimited txt file into an array (works well). I used tab, as some fields in the original csv contains commas.
      However, I needed autoit to manipulate this array, and output it as a csv.
      IF my array contains items with a comma, without double quotes around the field, then how best do I get a csv out of this?
      My current workaround is to filewritefromarray tab delimited, then open it in excel and save as a csv. I will need to check this to see how the address fields behave that contain a comma.
       
      Any thoughts would be appreciated.
       
    • Skeletor
      By Skeletor
      Hi All,

      I would like to know how you would take a FileLineRead and insert it into an array which then inserts it into Excel?
      One thing to know is the files content is broken up, so I only use half of the content within $FileRead1.
      So its imperative that the $value1, $value2, etc variables be used. 
      Code below:
      $FileRead1 = FileReadLine("C:\temp\sample.txt",1) For $count = 1 To _FileCountLines($FileRead1) Step 1 $string = FileReadLine($FileRead1, $count) $input = StringSplit($string, ",", 1) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] $value4 = $input[4] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value1, "A1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value2, "B1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value3, "C1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value4, "D1") Next  
    • AnonymousX
      By AnonymousX
      Hello,
      I'm trying to write a script that moves copies excel cells into an array. I'll than manipulate the values and send array into another program. 
      I don't want range to be specific to a workbook, or sheet, or set of cells.
      I want user to be able to highlight desired cells and to copy either normally ("Ctrl+C") or by a hotkey ("Alt+C"). 
      Could someone help me with this?
      Thank you,
      I've tried to write the framework: (edited)
      #include <MsgBoxConstants.au3> #include <Array.au3> #include <Excel.au3> HotKeySet("!v", "Pastedata") While True Sleep(1000) WEnd func Makearray() local $bArray ;User has cells already copied ;Convert clipboard into an array ;I don;t know how excel stores data to clipboard so don;t know how to bring it into array _Arraydisplay($bArray) MsgBox(0,0,$bArray) return $bArray endfunc func Pastedata() Local $aArray MsgBox(0,0,"wait",1) ;make array based on assumption user has already copied a range to clipboard $aArray = Makearray() ;paste code ;don;t worry about this I got the rest endfunc  
    • Dzenan03
      By Dzenan03
      I want to make a while loop, that creates variables based on a array. For thist I created the array $iDsO with the number and the name of folders in an other folder. Every folder has a different name an I want to create variables(arrays) for each folder that show me all the files in that folder. For example: I have the Folder \Folder1. In it there are the Folders \1, \2, \3. In 1, 2 and 3 there are some files(.png). The array for Folder1 is $iDsO and now I want to crate the arrays $iDsO1, $iDsO2 and $iDsO3 with the files in them can I make something like this:
      While $iDs > 0 ;$iDs is the number of files in Folder1>> $iDsO[0] $iDs#here should come the Foldername for example '1'# = _FileListtoArray(@ProgramFilesDir&"\Folder1\"&$iDsO[$iDs]) $iDs = $iDs - 1 Wend So that in the End I have three variabels ($iDs1, $iDs2 and $iDs3)
       
      Is this posible or if not what could I do instead ( I don´t know the number of folders in Folder1 in the begining).
×