Jump to content

Recommended Posts

Posted (edited)

Hello!

I have a text file containing FOLLOWING

john: 1234569

ana: 55366696

Johanson: 2536

and I want to open it and make it look like this with - $file = FileOpen(@TempDir & "test.txt", 0):

(file will have more lines)

john : 1234569

ana : 55366696

Johanson : 2536

how can I do that with AUTOIT?

Thanks in advance!

Edited by lastmember
Posted (edited)

Look into StringRegExp, to get array of the data.

Then loop through, with StringLen, to get the max len, and append spacing (to those shorter than max len) until it reaches the max stringlen.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Posted (edited)

: To be after the longest name

[font=courier new,courier,monospace]john     : 1234569
ana      : 55366696
Johanson : 2536[/font]
Edited by lastmember
Posted

#include <Array.au3>
$string = "john: 1234569" & @CRLF & _
"ana: 55366696" & @CRLF & _
"Johanson: 2536"
$array = StringRegExp($string,"(.*)\:(.*)", 4)
$iMaxLen = 0
For $i = 0 To UBound($array) - 1
 $temp = $array[$i]
;~  _ArrayDisplay($temp)
 If StringLen($temp[1]) > $iMaxLen Then $iMaxLen = StringLen($temp[1])
Next
$iMaxLen+=1 ; add the trailing space
For $i = 0 To UBound($array) - 1
 $temp = $array[$i]
 While StringLen($temp[1]) < $iMaxLen
  $temp[1] &= " "
 WEnd
 ConsoleWrite($temp[1] & ":" & $temp[2])
Next

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Posted (edited)

Well, the variable is there for the string...what function should you call to read the text of a file? Look in the helpfile.

File*

or

_File* functions

Use the above function to populate the variable.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Posted

#include 
$file = FileOpen(@TempDir & "\test.txt", 0)
$chars = FileRead($file)
$array = StringRegExp($chars,"(.*)\:(.*)", 4)
$iMaxLen = 0
For $i = 0 To UBound($array) - 1
$temp = $array[$i]
;~ _ArrayDisplay($temp)
If StringLen($temp[1]) > $iMaxLen Then $iMaxLen = StringLen($temp[1])
Next
$iMaxLen+=1 ; add the trailing space
For $i = 0 To UBound($array) - 1
$temp = $array[$i]
While StringLen($temp[1]) < $iMaxLen
$temp[1] &= "."
WEnd
ConsoleWrite($temp[1] & $temp[2])
Next
FileClose($file)

YES IT IS OK !

merci beaucoup !

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.
×
×
  • Create New...