AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Remove last character from string (https://forums.alliedmods.net/showthread.php?t=340480)

kww 11-21-2022 09:46

Remove last character from string
 
First thing that came in my mind was:
PHP Code:

public test(id)
{
    
//MagicNumbers™
    
new szBuffer[190], szBuffer2[4], len;

    for(new 
i10i++)
    {
        
len += formatex(szBuffer2charsmax(szBuffer2), " %i,"i);
        
add(szBuffercharsmax(szBuffer), szBuffer2);
    }

    
szBuffer[len 1] = ""// Marked

    
console_print(id"%s"szBuffer);


But marked string gives me an error 006: must be assigned to an array
Any good way to solve this?

jimaway 11-21-2022 09:56

Re: Remove last character from string
 
szBuffer[len - 1] = 0;

Bugsy 11-21-2022 10:12

Re: Remove last character from string
 
You may also see EOS used in code, which is the same as using 0 and represents 'End Of String'. The goal is to set the desired array position as null, which signifies the end of null-terminated strings.

szBuffer[len - 1] = EOS;


All times are GMT -4. The time now is 15:39.

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