Jump to content

Write different array(s) on the same file


Recommended Posts

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 ;)

Link to post
Share on other sites

Use function _ArrayConcatenate to concatenate the arrays.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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 post
Share on other sites

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

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 2022-02-19 - Version 1.6.1.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 (NEW 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 post
Share on other sites

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 2022-02-19 - Version 1.6.1.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 (NEW 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 post
Share on other sites

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

Link to post
Share on other sites

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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 post
Share on other sites

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

Link to post
Share on other sites

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 2022-02-19 - Version 1.6.1.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 (NEW 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 post
Share on other sites

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
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By TheAlienDoctor
      Hi, I was looking into creating a script that would detect if a file exists, then move it (and in some cases rename it, depending on the file) as well as write to a log file.
      The issue is, there is a lot of files that need to be moved, sometimes some files will exist and others won't depending on the use-case. However if a file does exist, it will always be going into the same directory with the same name.
      Currently I have an array nested inside of the array, with each array inside that array having both the old and new directory, and then a For loop to actually run through and do the file transferring. The issue I am having is how to call the Array inside of the array, because how do I specify  which the old directory is and which the new is?
      Global $FileTransfer[2000] = [Global $Dir1[2] = ["original dir 1", "new dir 1"], Global $Dir2[2] = ["original dir 2", "new dir 2"]] For $FileTransfer = [0] To [1] Step +1 If FileExists({original dir}) Then FileMove({original dir}, new dir, 1) FileOpen("log.latest.txt", 1) FileWrite("log.latest.txt", "{original dir} found, moved it to new dir." & @CRLF) FileClose("log.latest.txt") Else FileOpen("log_latest.txt", 1) FileWrite("log_latest.txt", "{original dir} not found, ignoreing it." & @CRLF) FileClose("log_latest.txt") EndIf Next I have put what I want the old and new directory to be for each array in {}, so hopefully its easier to tell which part is working and whats not.

      I am still reasonably new to AutoIT, any help is appreciated. Thankyou
    • By arunkw
      I have a spreadsheet - daily routine which has two columns: activity and time as shown here
      | Activity             | Time     | |----------------------|----------| | Sleep               |  6:00 am | | Toilet              |  6:15 am | | Get ready for gym  |  6:30 am | | Exercise            |  7:50 am | | ... more things      |  9:00 pm | | ... still more       | 10:45 pm | | Sleep               |  6:00 am |   I wanted to find out, say in C1 which activity is current for me using now() I.e., if it’s 6:45am on my watch, it should show me Exercise  in C1 Thanks to Adam D. PE, this formula works like magic to get the result =VLOOKUP(MOD(NOW(),1),{B2:B,A2:A},2,1)   Now, I want to reproduce same result in autoit, how to do that? To have easy solution say, I copy-paste spreadsheet data in array directly in code, right? Use for loop and run the above vlookup function and show the answer using tooltip. How to achieve this? please help.  
    • By goku200
      I have an Autoit script that lists files from a folder into an array list. Is there a way to separate the filenames by an underscore and include the id, version, name and date into separate columns in Excel.
      Example of filename:
      12345_v1.0_TEST Name [12345]_01.01.2022.html
      12345 would be in one column
      v1.0 would be in another column
      TEST Name [12345] would be in another column
      01.01.2022 would be in another column
      .html would be in another column
      Note: filenames always change each day.
      Here is my code that lists the files into column C and then writes the column Headers into Column D, E, F, G. Just need some help with separating them into columns by the _ delimiter
       
    • By mLipok
      Usually when I collect data from DataBase I need to give EndUser a possibility to select rows which should be taken in the processing loop.
      I was searching on the forum and I'm not able to find any UDF or even example of how to select data from array.
      I have my own solutions but I think they are not worth posting on the forum as it is very old code and I am looking for a better solution.

      Could anybody point me to some examples/solutions ?

      Thank you in advance.
      @mLipok
    • By EmilyLove
      I have a string containing the full path of an executable and an array of executables without their paths. I am trying to compare the string to the list in the array and if a match is found, remove it from the array. The entry get removed from the array successfully, and after checking its return result, uses it to update the ubound if it succeeded, but it doesn't want to update to the new value. Any ideas what I am doing wrong? It acts like it is read-only.
      #include <Array.au3> #include <File.au3> Local $sApp_Exe = "F:\App\Nextcloud\nextcloud.exe" Local $aWaitForEXEX = [3, "Nextcloud.exe", "nextcloudcmd.exe", "QtWebEngineProcess.exe"] For $h = 1 To $aWaitForEXEX[0] If StringInStr($sApp_Exe, $aWaitForEXEX[$h]) <> 0 Then $iRet = _ArrayDelete($aWaitForEXEX, $h) If $iRet <> -1 Then $aWaitForEXEX[0] = $iRet ;this line doesn't work. $aWaitForEXEX[0] doesn't update and shortly gives Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded.: _ArrayDisplay($aWaitForEXEX) EndIf Next  
×
×
  • Create New...