GO2cam Javascript API  6.11
GO2SAsciiFile Class Reference

Class to manage Ascii files. More...

Inheritance diagram for GO2SAsciiFile:
GO2SFile GO2SCsvFile

Public Member Functions

 GO2SAsciiFile (String fileName, GO2SEnum::GO2SFileOpen mode=GO2SEnum::GO2SFileOpen::read_only)
 
GO2SEnum::GO2SError Append (Number pos, String line)
 
GO2SEnum::GO2SError AppendLast (String line)
 
GO2SEnum::GO2SError DeleteLine (Number no)
 
GO2SEnum::GO2SError EditLine (Number no, String newLine)
 
Number GetLineCount ()
 
Array< String > ReadAll ()
 
String ReadLine (Number no)
 
- Public Member Functions inherited from GO2SFile
void Close ()
 Close the file.
 
String GetFilePath ()
 Get the full path (directory + name) of the file.
 
Boolean IsOpen ()
 Get if the file is open.
 
void Save ()=0
 

Detailed Description

Class to manage Ascii files.

Exemple:

//open the file
var file = new GO2SAsciiFile('u:\\ascii.txt', GO2SFileOpen.read_write)
//Access content
console.log('file number of lines: ' + file.GetLineCount())
console.log('file content:\n' + file.ReadAll())
console.log('file 4th line is: ' + file.ReadLine(3))
//Change content
file.DeleteLine(3)
file.EditLine(3, 'end of file')
file.Save()
file.Close()
file = new GO2SAsciiFile('u:\\ascii.txt')
console.log('new file content:\n' + file.ReadAll())
file.Close()
Class to manage Ascii files.
Definition GO2SAsciiFile.hpp:40
Array< String > ReadAll()
Definition GO2SAsciiFile.hpp:62
Number GetLineCount()
Definition GO2SAsciiFile.hpp:53
String ReadLine(Number no)
GO2SAsciiFile(String fileName, GO2SEnum::GO2SFileOpen mode=GO2SEnum::GO2SFileOpen::read_only)
GO2SEnum::GO2SError EditLine(Number no, String newLine)
GO2SEnum::GO2SError DeleteLine(Number no)
void Close()
Close the file.
Definition GO2SFile.hpp:15
void Save()=0

output:

file number of lines: 5
file content :
Hello World !, This is my ascii file, enjoy it !, line 4, last line
file 4th line is : line 4
new file content :
Hello World !, This is my ascii file, enjoy it !, end of file

Constructor & Destructor Documentation

◆ GO2SAsciiFile()

GO2SAsciiFile::GO2SAsciiFile ( String fileName,
GO2SEnum::GO2SFileOpen mode = GO2SEnum::GO2SFileOpen::read_only )

Create new or open existing ascii file

Warning
The closing of the file is automatically handled
Parameters
[in]fileNamefull path of the file (directory + name)
[in]modeopening mode

Member Function Documentation

◆ Append()

GO2SEnum::GO2SError GO2SAsciiFile::Append ( Number pos,
String line )

Add a line at a given position

Returns
GO2SError.success if success, see GO2SError otherwise
Parameters
[in]posposition for the new line, starting at 0.
[in]linenew line

◆ AppendLast()

GO2SEnum::GO2SError GO2SAsciiFile::AppendLast ( String line)
inline

Add a line at the end of the file

Returns
GO2SError.success if success, see GO2SError otherwise
Parameters
[in]linenew line

◆ DeleteLine()

GO2SEnum::GO2SError GO2SAsciiFile::DeleteLine ( Number no)

Delete a line

Returns
GO2SError.success if success, see GO2SError otherwise
Parameters
[in]noline number to delete starting at 0

◆ EditLine()

GO2SEnum::GO2SError GO2SAsciiFile::EditLine ( Number no,
String newLine )

Replace a line by a new line

Returns
GO2SError.success if success, see GO2SError otherwise
Parameters
[in]noline number to replace starting at 0
[in]newLinenew line text

◆ GetLineCount()

Number GO2SAsciiFile::GetLineCount ( )
inline
Returns
the number of lines

◆ ReadAll()

Array< String > GO2SAsciiFile::ReadAll ( )
inline
Returns
all lines of the file in an array

◆ ReadLine()

String GO2SAsciiFile::ReadLine ( Number no)

Read a line

Remarks
return an empty string if no is out of range
Parameters
[in]noline number to be read, starting at 0