Raised This Month: $32 Target: $400
 8% 

Solved Remove last character from string


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 11-21-2022 , 09:46   Remove last character from string
Reply With Quote #1

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?
__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951

Last edited by kww; 11-21-2022 at 10:09.
kww is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 11-21-2022 , 09:56   Re: Remove last character from string
Reply With Quote #2

szBuffer[len - 1] = 0;
jimaway is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-21-2022 , 10:12   Re: Remove last character from string
Reply With Quote #3

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;
__________________

Last edited by Bugsy; 11-21-2022 at 10:12.
Bugsy is offline
Reply



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 19:29.


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