Sign in to follow this  
Followers 0
giorg70

The Last Character in a file

6 posts in this topic

Is it possible to read the last character in a file and if it isn't an expected value, add it to the end?

Thanks in advance

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Is it possible to read the last character in a file and if it isn't an expected value, add it to the end?

Thanks in advance

This will give you the last character:

#include <File.au3>

Global $Array
Global $lines_count
Global $Text_line
Global $Chr_count
Global $Chr_last


_FileReadToArray( "Text.txt" , $Array );;Reading the file to an Array
If (not IsArray( $Array )) or (@error) Then
    Exit
EndIf

$lines_count  =  $Array [0];;Number of lines in the file.

;Now will take the last line.
$Text_line = $Array[$lines_count]

;Removing white spaces becuase you don't want the last character to be a white space.
$Text_line = StringStripWS( $Text_line , 8 )

;Now will split all the characters in the line and save to $Array
$Array = StringSplit( $Text_line , '' )

$Chr_count = $Array[0];;Number of characters in the last line.

$Chr_last = $Array[$Chr_count];This is the last character.

MsgBox( 0 , "Last Character is:" , $Chr_last )
Edited by rbhkamal

"When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix

Share this post


Link to post
Share on other sites

Thank you very much!!! Example: the last caharcter is '.' but i need this file finish with '<009>', is it possible to use FileWriteLine?

In the case that i'm working with strings, is it possible to retrieve the last character? And append some characters to the end?

Share this post


Link to post
Share on other sites

Thank you very much!!! Example: the last caharcter is '.' but i need this file finish with '<009>', is it possible to use FileWriteLine?

In the case that i'm working with strings, is it possible to retrieve the last character? And append some characters to the end?

Read the help about FileWriteLine() and FileWrite(), FileWriteLine() will append another line to your file and then add '<009>'.

"When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix

Share this post


Link to post
Share on other sites

OK!, for manage strings i open another topic

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

This will give you the last character:

#include <File.au3>

Global $Array
Global $lines_count
Global $Text_line
Global $Chr_count
Global $Chr_last
_FileReadToArray( "Text.txt" , $Array );;Reading the file to an Array
If (not IsArray( $Array )) or (@error) Then
    Exit
EndIf

$lines_count  =  $Array [0];;Number of lines in the file.

;Now will take the last line.
$Text_line = $Array[$lines_count]

;Removing white spaces becuase you don't want the last character to be a white space.
$Text_line = StringStripWS( $Text_line , 8 )

;Now will split all the characters in the line and save to $Array
$Array = StringSplit( $Text_line , '' )

$Chr_count = $Array[0];;Number of characters in the last line.

$Chr_last = $Array[$Chr_count];This is the last character.

MsgBox( 0 , "Last Character is:" , $Chr_last )

oÝ÷ Ûú®¢×mmç²'«¶î²×h¶¬jëh×6$LastCharacter = StringRight(FileRead('SomeTxtFile.txt'), 1)
MsgBox(64, 'Info', $LastCharacter)oÝ÷ ØGb´-¹©eÊØb±Ú³Z·*.­«$xºÚ"µÍÑ[TXÙSÝÚ ÌÎNÑ[SØØ][Û   ÌÎNË ÌÎNÉÌIÝÉÌÎNÊB[ÈÑ[TXÙSÝÚ   ÌÍÚ[S[YK ÌÍÜÐÚXÚÊBSØØ[  ÌÍÜÑXYH[TXY
    ÌÍÚ[JBRYÝ[ÔYÚ
    ÌÍÜÑXYÝ[Ó[    ÌÍÜÐÚXÚÊJH   ÉÝÈ  ÌÍÜÐÚXÚÈ[BIÌÍÚÜ[H[SÜ[   ÌÍÚ[KBBQ[UÜ]J   ÌÍÚ[S[YKÝ[Õ[TYÚ
    ÌÍÜÑXYJH    [È ÌÍÜÐÚXÚÊBBQ[PÛÜÙJ ÌÍÚÜ[BQ[Y[Y
(This FileRead() option without FileGetSize() needs Beta)
Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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  
Followers 0