Raised This Month: $ Target: $400
 0% 

Solved Manipulate string in file


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 12-15-2020 , 22:26   Re: Manipulate string in file
Reply With Quote #5

Quote:
Originally Posted by Bugsy View Post
I am having no issue. Though, I am working on very little.. you have not said what exactly you are trying to do or what the source file contents look like. If you need help, provide the problem at hand, not your troubleshooting.

PHP Code:
public a()
{
    new 
iFile fopen"abc123.txt""rt" );
    
    new 
0
    
    
if(iFile)
    {
        new 
szData[120], szData1[120]
    
        while(
fgets(iFileszDatacharsmax(szData)))
        {
            
i++
            switch(
szData[0])
            {
                case 
EOS';''/': continue
                default:
                {
                    new 
iz parse(szDataszData1charsmax(szData1))
    
                    
server_print("[%s]" szData1)                        
                        
                
                }
            }
        }
    
        
fclose(iFile)
    }

Source file
Code:
Test line1
Test line2
Test line3
Test line4
Test line5
Test line6
Test line7
Test line8
T1119
T1110
T1111
T1112
Output
PHP Code:
[Test]
[
Test]
[
Test]
[
Test]
[
Test]
[
Test]
[
Test]
[
Test]
[
T1119]
[
T1110]
[
T1111]
[
T1112
I'll be as clear as possible, because I don't think you understand.

Let's use the function below as a test to remove an admin for example, after finding the line with steamid I remove it ok?

PHP Code:
public RemoveAdminHandler(id)
{
    
get_user_authid(g_AdminTarget[id], playerinfocharsmax(playerinfo));

    new 
szConfig[MAX_FMT_LENGTH]
    
get_configsdir(szConfigcharsmax(szConfig))
    
add(szConfigcharsmax(szConfig), "/users.ini")

    new 
iFile fopen(szConfig"rt")

    
0

    
if(iFile)
    {
        new 
szData[120], szData1[120]

        while(
fgets(iFileszDatacharsmax(szData)))
        {
            
i++
            switch(
szData[0])
            {
                case 
EOS';''/''[': continue
    
                default:
                {
                    
parse(szDataszData1charsmax(szData1))

                    if(
equal(szData1playerinfo))
                    {
                        
write_file(szConfig"^r"i-1)
                        
server_cmd("amx_reloadadmins")
                        break
                    }
                }
            }
        }

        
fclose(iFile)
    }

    return 
PLUGIN_HANDLED

In the attachment I put user.ini (which is the test before deletion) and users - after.ini (which is after removing the line), notice that in the 1st line of the "after" file there is an "invisible" space.
Attached Files
File Type: ini users - after.ini (1 Bytes, 42 views)
File Type: ini users.ini (47 Bytes, 33 views)
__________________


Quote:
Originally Posted by fysiks View Post
Please stop trying to help. You appear to just be posting random stuff. Wait until you actually understand more about AMX Mod X and how the game works.
https://iceeedr.com.br/
iceeedr is offline
Send a message via Skype™ to iceeedr
 



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 14:13.


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