SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 28/01/2020, 03:46 AM   #1
Radless
Little Clucker
 
Join Date: Jul 2019
Posts: 43
Reputation: 3
Default Null Character

I maked remove color code from string;

Code:
stock RemoveColorFromString(string[])
{
	new m[256];
	
	format(m, sizeof m, "%s", string);
	
	for (new i = 0, len = strlen(m); i < len; i ++)
	{
 		if (m[i] == '{')
		{
			m[i] = ' ';
			m[i+1] = ' ';
			m[i+2] = ' ';
			m[i+3] = ' ';
			m[i+4] = ' ';
			m[i+5] = ' ';
			m[i+6] = ' ';
			m[i+7] = ' ';
		}
	}
	return m;
}
But it does not delete the character, it replaces the character to space
Radless is offline   Reply With Quote
Old 28/01/2020, 10:14 AM   #2
Zoxy
Little Clucker
 
Join Date: Jan 2020
Posts: 5
Reputation: 0
Default Re: Null Character

Code:
stock RemoveColorFromString(string[])
{
	new m[256];
	
	format(m, sizeof m, "%s", string);
	
	for (new i = 0, len = strlen(m); i < len; i ++)
	{
 		if (m[i] == '{')
		{
		     strdel(m, i, i + 7);
		}
	}
	return m;
}
Zoxy is offline   Reply With Quote
Old 28/01/2020, 01:17 PM   #3
Shamans
Little Clucker
 
Shamans's Avatar
 
Join Date: Oct 2019
Posts: 12
Reputation: 0
Default Re: Null Character

Why use the second variable? When you have an argument string
My option will somehow be easier to behave.
PHP Code:
stock RemoveColorFromString(string[]){
    
    new 
result strfind(string,"{");
    if(
result != -1)
        
strdel(stringresultresult+9);

Also spent your choice through the profiler, it also doesn 't work. My varinth is more stable. Also below I will provide an example of using

Quote:
[18:15:15] Option Zoxy: 31070
[18:15:15] Option Shamans: 12472

Last edited by Shamans; 28/01/2020 at 02:14 PM.
Shamans is offline   Reply With Quote
Old 28/01/2020, 03:23 PM   #4
Zoxy
Little Clucker
 
Join Date: Jan 2020
Posts: 5
Reputation: 0
Default Re: Null Character

Quote:
Originally Posted by Shamans View Post
Why use the second variable? When you have an argument string
My option will somehow be easier to behave.
PHP Code:
stock RemoveColorFromString(string[]){
    
    new 
result strfind(string,"{");
    if(
result != -1)
        
strdel(stringresultresult+9);

Also spent your choice through the profiler, it also doesn 't work. My varinth is more stable. Also below I will provide an example of using
It will only delete one color code when multiple color codes are used. I tested the function, it works:

Code:
RemoveColorFromString(string[]){
    
	for (new i = 0, len = strlen(string); i < len; i ++)
	{
		if(string[i] == '{')
		{
			strdel(string, i, i + 8);
                        i += 8;
		}
	}
}
Example:

Code:
new color[50];
strcat(color, "{FFFFFF}Hello! My name is {ff0d00}Zoxy");
RemoveColorFromString(color);
printf("%s", color);
Zoxy is offline   Reply With Quote
Old 28/01/2020, 04:05 PM   #5
Radless
Little Clucker
 
Join Date: Jul 2019
Posts: 43
Reputation: 3
Default Re: Null Character

Quote:
Originally Posted by Zoxy View Post
It will only delete one color code when multiple color codes are used. I tested the function, it works:

Code:
RemoveColorFromString(string[]){
    
	for (new i = 0, len = strlen(string); i < len; i ++)
	{
		if(string[i] == '{')
		{
			strdel(string, i, i + 8);
                        i += 8;
		}
	}
}
Example:

Code:
new color[50];
strcat(color, "{FFFFFF}Hello! My name is {ff0d00}Zoxy");
RemoveColorFromString(color);
printf("%s", color);
Thank you, it worked.
Radless is offline   Reply With Quote
Old 28/01/2020, 07:32 PM   #6
Shamans
Little Clucker
 
Shamans's Avatar
 
Join Date: Oct 2019
Posts: 12
Reputation: 0
Default Re: Null Character

Quote:
Originally Posted by Zoxy View Post
It will only delete one color code when multiple color codes are used. I tested the function, it works:

Code:
RemoveColorFromString(string[]){
    
	for (new i = 0, len = strlen(string); i < len; i ++)
	{
		if(string[i] == '{')
		{
			strdel(string, i, i + 8);
                        i += 8;
		}
	}
}
Okay, I 've redone my job a little bit.
It also stayed faster than yours and also works. Profiler 1000 players - 10,000 iterations. You will see the speed comparison in the comment

PHP Code:
new string[][] = {
    {
"{ffffff}Hello in world {ffffff}assembler"},
    {
"Hello in world {ffffff}dotvante"}
};

InitArray() // Yours code
{
    new 
randoms random(2);

    for (new 
0len strlen(string[randoms]); len++)
    {
        if(
string[randoms][i] == '{')
        {
            
strdel(string[randoms], i8);
               
+= 8;
        }
    }
}

InitNoArray() // My code
{
    new 
randoms random(2);

    
altern:
    new 
result strfind(string[randoms],"{");
    if(
result != -1){
        
strdel(string[randoms], resultresult+9);
        goto 
altern;
    }

Speed performance of a task
Quote:
You option: 17659
My option Shamans: 5290
Shamans is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
(null) GoldenLion Scripting Help 15 01/01/2017 06:19 PM
Setting character spawn after making a character AMouldyLemon Scripting Help 6 23/06/2014 06:23 PM
Deleting Character and Creating Character dialog. AMouldyLemon Scripting Help 9 23/06/2014 04:01 PM
Name Goes Null Necro[ABK] Scripting Help 13 04/03/2014 02:40 PM
NULL or not NULL, that is the question dusk Scripting Help 4 18/11/2013 10:06 AM


All times are GMT. The time now is 02:55 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.