Hi,
I'd like insert text into a file txt.
BEFORE
STATE - ITALY FROM ITALY
CITY LECCE FROM LECCE
ADDRESS VIA ROMA 8
AFTER
STATE - ITALY FROM ITALY
NAME - MARIO ROSSI
CITY LECCE FROM LECCE
ADDRESS VIA ROMA 8
thanks
local aLines := hb_aTokens( hb_memoRead( "test.txt" ), CRLF )
local cText := ""
AIns( aLines, 2 )
aLines[ 2 ] = "NAME - MARIO ROSSI"
AEval( aLines, { | cLine | cText += cLine + CRLF } )
? hb_memoWrit( "test.txt", cText )
? hb_memoRead( "test.txt" )
HB_MEMOREAD() vs MEMOREAD(): HB_MEMOREAD() is identical to MEMOREAD() except it won’t truncate the last byte (on non-UNIX compatible systems) if it’s a EOF char.
static HB_BOOL hb_memowrit( HB_BOOL bHandleEOF )
{
const char * pszFileName = hb_parc( 1 );
PHB_ITEM pString = hb_param( 2, HB_IT_STRING );
HB_BOOL bRetVal = HB_FALSE;
if( pszFileName && pString )
{
PHB_FILE pFile = hb_fileExtOpen( pszFileName, NULL,
FO_READWRITE | FO_EXCLUSIVE | FO_PRIVATE |
FXO_TRUNCATE | FXO_SHARELOCK,
NULL, NULL );
if( pFile != NULL )
{
HB_SIZE nSize = hb_itemGetCLen( pString );
const char * pData = hb_itemGetCPtr( pString );
while( nSize > 0 )
{
HB_SIZE nWritten = hb_fileWrite( pFile, pData, nSize, 0 );
if( nWritten == 0 || nWritten == ( HB_SIZE ) FS_ERROR )
break;
nSize -= nWritten;
pData += nWritten;
}
bRetVal = nSize == 0;
/* NOTE: CA-Cl*pper will add the EOF even if the write failed. [vszakats] */
/* NOTE: CA-Cl*pper will not return .F. when the EOF could not be written. [vszakats] */
if( bHandleEOF && bRetVal ) /* if true, then write EOF */
{
char cEOF = HB_CHAR_EOF;
hb_fileWrite( pFile, &cEOF, sizeof( char ), -1 );
}
hb_fileClose( pFile );
}
}
return bRetVal;
}
HB_FUNC( HB_MEMOWRIT )
{
hb_retl( hb_memowrit( HB_FALSE ) );
}
HB_FUNC( MEMOWRIT )
{
hb_retl( hb_memowrit( HB_TRUE ) );
}
/* NOTE: CA-Cl*pper will add the EOF even if the write failed. [vszakats] */
/* NOTE: CA-Cl*pper will not return .F. when the EOF could not be written. [vszakats] */
if( bHandleEOF && bRetVal ) /* if true, then write EOF */
{
char cEOF = HB_CHAR_EOF;
hb_fileWrite( pFile, &cEOF, sizeof( char ), -1 );
}
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 68 guests