Raised This Month: $ Target: $400
 0% 

read_file ( const file[], line, text[], len, &txtLen )


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-09-2011 , 10:50   Re: read_file ( const file[], line, text[], len, &txtLen )
Reply With Quote #9

PHP Code:
//Read first line in a file
new szLine32 ] , iLen;
read_file"test.txt" szLine charsmaxszLine ) , iLen );

//Overwrite first line in file
write_file"test.txt" "last.bat" ); 
You can use this to search for a line of text containing a keyword and replace it with a new line. It will return -1 if file doesnt exist, 0 if file exists but searched item was not found, 1 if searched item found and replaced.
PHP Code:
public ReplaceLineItem( const szFile[] , const szItemToFind[] , const szNewLine[] )
{
    new 
iFilePos szLineItem512 ] , bool:bFound iFileHandle;

    if ( !( 
iFileHandle fopenszFile "rt" ) ) )
        return -
1;

    while ( !
feofiFileHandle ) )
    {
        
iFilePos++;
        
        if ( !
fgetsiFileHandle szLineItem charsmaxszLineItem ) ) )
            continue;
        
        if( 
containiszLineItem szItemToFind ) >= 0  )
        {
            
write_fileszFile szNewLine iFilePos );
            
bFound true;
            break;
        }
    }
    
    
fcloseiFileHandle );

    return 
bFound;

__________________

Last edited by Bugsy; 08-09-2011 at 11:17.
Bugsy is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:27.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode