Jump to content
Sign in to follow this  
lastmember

ALIGNMENT...

Recommended Posts

lastmember

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

Share this post


Link to post
Share on other sites
jdelaney

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.

Share this post


Link to post
Share on other sites
UEZ

What are the rules for the alignment?

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
lastmember

I am a beginner, you can post an example?

Share this post


Link to post
Share on other sites
lastmember

: To be after the longest name

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

Share this post


Link to post
Share on other sites
jdelaney

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

Share this post


Link to post
Share on other sites
lastmember

thanks for promptly

but I want to read from a text file and save it in another file, how to do that?

Share this post


Link to post
Share on other sites
jdelaney

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.

Share this post


Link to post
Share on other sites
lastmember

#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 !

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.