Jump to content

FileWriteFromArray Help


Recommended Posts

Little help understanding why and how to correct this issue please.    Here is my code:

$sFilePath = ("C:\Temp\test.txt")
$sFile = FileRead($sFilePath)

;-----Pull Data from file----  Data is two sets of addresses Name1  and Name2
$aResults = StringRegExp($sFile, "(?i)(Name1.*\R.*\R.*\R.*)\R|(?i)(Name2.*\R.*\R.*\R.*)\R", 3)

; Some blank lines get pulled --  This deletes blank lines
while 1
    $newvar = _ArraySearch($aResults, "", 0, 0, 0, false); Search for null lines
    if @error = 6 Then; no more matches found
        ExitLoop
    Else
        _ArrayDelete($aResults, $newvar);Delete current full line
    EndIf
wend

; This takes the two sets of addresses and puts them on one line So each line starts with Name1
Local $aFinalResults[UBound($aResults)]

For $i = 0 to UBound($aResults) -1
   $aFinalResults[$i] = $aResults[$i] & " " & $aResults[$i+1]
   $i = $i+1
Next

For $i = UBound($aFinalResults) -1 To 0 Step -1
   If $aFinalResults[$i] = "" Then
       _ArrayDelete($aFinalResults, $i)
   EndIf
Next

_ArrayDisplay($aFinalResults)

_FileWriteFromArray("C:\Temp\temp.txt", $aFinalResults)

The ArrayDisplay is displaying the data exactly how I want it to be.  Name1 and Name2 addresses on a single line.  So each line in the ArrayDisplay looks like this:

Name1 street city state Name2 street city state

But once I do the FileWriteFromArray the temp.txt file looks like this:

Name1

street

city state  Name2

street

city state

How do I get the FileWriteFromArray to  write how the ArrayDisplay is showing the data?

Thank you for any help

Link to comment
Share on other sites

Use the $sDelimiter parameter for the function to make sure it writes it all on one line per row of the array. In your case you'd probably want to use either a space or a tab character to do it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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