Jump to content
Sign in to follow this  
mrtweaver

Arrrays and spaces

Recommended Posts

mrtweaver

Good day, i have question concerning arrays. I am attempting to load this text file, the text file is in four columns. The problem is the program that wrote the text file does not allow changing of the delimiter between columns, and the amount of delimiting characters is different between each column.

Like between column 1 and column 2 there is 10 spaces (hex 20), between column 2 and column 3 there are 8 spaces (hex 20), and between column 3 and column 4 there are 15 spaces (hex 20)

When i run the array.au3 and i use space as my delimiter, it crashes because not all spaces are equal or at least that is what i am thinking is the case.

If I use a program like ultra edit or notepad and i go through the raw code and i take out all the spaces between each column and i replace with say 1 tab, then use tab as my delimeter, it works fine. But i dont want to have to do that if there is an easier approach that maybe someone on here has come up with.

So any ideas on how to combat the issue of the extra spaces?

Thanks for looking and have a great day.

 

 

Share this post


Link to post
Share on other sites
mrtweaver

Ok here is the code.

 

    Local Const $sFilePath = "\mail\18960006.pdr"

 

   

    ; Open the file for reading and store the handle to a variable.

    Local $hFileOpen = FileOpen($sFilePath, $FO_READ)

    If $hFileOpen = -1 Then

        MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.")

        Return False

    EndIf

 

    ; Read the contents of the file using the handle returned by FileOpen.

    Local $sFileRead = FileRead($hFileOpen)

 

    ; Close the handle returned by FileOpen.

    FileClose($hFileOpen)

 

    ; Display the contents of the file.

            $aArray = $aArray_Base

            _ArrayAdd($aArray, $sFileRead ,Default, " ", Default, Default)

 

            _ArrayDisplay($aArray, "Data of file")

Share this post


Link to post
Share on other sites
mrtweaver

Was not sure how to add the code in so that one could see it as it would be seen on AutoIT. But I did do a recalculation and the number of spaces are as follow:

Between column 1 and 2 there are 11, between column 2 and 3 there are 7, and between column 3 and 4 there are 21

At least at the end of the file is the CRLF so that much works, it is just when there is more than 1 space the array function does not seem to like it.

Share this post


Link to post
Share on other sites
JohnOne

No idea why it would crash upon multiple spaces, I suspect it's something else, but try this to remove multiple spaces.

Local $sFileRead = StringStripWS(FileRead($hFileOpen), 4) ; 4 = $STR_STRIPSPACES strip double (or more) spaces between words

 


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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  

×