Raised This Month: $51 Target: $400
 12% 

Try to replace...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Shadow Of Death
Senior Member
Join Date: Jun 2005
Old 11-12-2011 , 22:01   Try to replace...
Reply With Quote #1

I try to replace . with _ in a string.
But i dont know what i do wrong.
Hope any can help me with this. I use the stock from Exolent http://forums.alliedmods.net/showthread.php?t=163205.

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <string_stocks>
.
.
.
new 
server_address[2][33];

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR);
    
register_clcmd("say /test","test")
    
    
get_cvar_string("ip"server_address[0], 32);
    
get_cvar_string("port"server_address[1], 32);
}

public 
test()
{
    
str_replace(server_address[0], 32".""_"01);
    
    
server_cmd("say IP: %s"server_address[0]);
    
server_cmd("say Port: %s"server_address[1]);
    return 
PLUGIN_CONTINUE;

it dosnt replace the dots.
__________________
Shadow Of Death is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-12-2011 , 23:23   Re: Try to replace...
Reply With Quote #2

Did you even try the most basic function yet? You should try the simplest functions first. replace_all() should work fine.
__________________
fysiks is offline
Old 11-13-2011, 02:15
Snaker beatter
This message has been deleted by Emp`. Reason: Irrelevant
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 11-13-2011 , 07:22   Re: Try to replace...
Reply With Quote #3

I don't think you should even use "_" but just simply type _ and .
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-13-2011 , 11:22   Re: Try to replace...
Reply With Quote #4

Quote:
Originally Posted by Napoleon_be View Post
I don't think you should even use "_" but just simply type _ and .
Wrong. Know what you're talking about if you're going to try to help others. You will end up just confusing them even more.

PHP Code:
replace_all string[], lenwhat[], with[] ) 
_ and . are symbols and the code would not compile. var[] means an array/string is expected.

PHP Code:
replace_allserver_address] , strlenserver_address] ) , "." "_" 
__________________
Bugsy is offline
Shadow Of Death
Senior Member
Join Date: Jun 2005
Old 11-13-2011 , 13:03   Re: Try to replace...
Reply With Quote #5

Thx again Bugsy,

think i ask more next time... try to code my first bigger plugin.
It work. But you know why the str_replace not work?
__________________
Shadow Of Death is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-13-2011 , 13:11   Re: Try to replace...
Reply With Quote #6

Quote:
Originally Posted by Shadow Of Death View Post
Thx again Bugsy,

think i ask more next time... try to code my first bigger plugin.
It work. But you know why the str_replace not work?
Not sure, I don't feel like looking at the stock. Just use replace_all(), it's less natives anyway.
__________________
Bugsy is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-13-2011 , 21:21   Re: Try to replace...
Reply With Quote #7

Quote:
Originally Posted by Shadow Of Death View Post
Thx again Bugsy,

think i ask more next time... try to code my first bigger plugin.
It work. But you know why the str_replace not work?
You seemed to have used it correctly but I couldn't figure out why it wouldn't work with your code.
__________________
fysiks is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 11-13-2011 , 23:41   Re: Try to replace...
Reply With Quote #8

Quote:
Originally Posted by Bugsy View Post
Not sure, I don't feel like looking at the stock. Just use replace_all(), it's less natives anyway.
Just a reminder, replace_all is not a native, but actually a stock:
Code:
/* Replaces a contained string iteratively.
 * This ensures that no infinite replacements will take place by
 *  intelligently moving to the next string position each iteration.
 */
stock replace_all(string[], len, const what[], const with[])
{
	new pos = 0;
	
	if ((pos = contain(string, what)) == -1)
	{
		return 0;
	}
	
	new total = 0;
	new with_len = strlen(with);
	new diff = strlen(what) - with_len;
	new total_len = strlen(string);
	new temp_pos = 0;
	
	while (replace(string[pos], len - pos, what, with) != 0)
	{
		/* jump to position after replacement */
		pos += with_len;
		
		/* update cached length of string */
		total_len -= diff;
		
		/* will the next call be operating on the last character? */
		if (pos >= total_len)
		{
			break;
		}
		
		/* find the next position from our offset */
		temp_pos = contain(string[pos], what);
		
		/* if it's invalid, we're done */
		if (temp_pos == -1)
		{
			break;
		}
		
		/* otherwise, reposition and update counters */
		pos += temp_pos;
		total++;
	}
	
	return total;
}
But your point still stands.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Shadow Of Death
Senior Member
Join Date: Jun 2005
Old 11-15-2011 , 18:55   Re: Try to replace...
Reply With Quote #9

Quote:
Originally Posted by fysiks View Post
...used it correctly .... it wouldn't work with your code.
Mysterious, that scares me.
__________________
Shadow Of Death is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-16-2011 , 02:46   Re: Try to replace...
Reply With Quote #10

Quote:
Originally Posted by Shadow Of Death View Post
Mysterious, that scares me.
Lol. It's probably something simple that's been overlooked. The question is: overlooked by whom?
__________________
fysiks 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 01:19.


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