SA-MP Forums Archive
Detect something from a string and replace it with something else?? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Detect something from a string and replace it with something else?? (/showthread.php?tid=156038)



Detect something from a string and replace it with something else?? - Fj0rtizFredde - 20.06.2010

Hello
I could really use some help here but Im not the best at explaining things.
But lets say that I type in: "Hello world" in the chat then I want to find the " " (space) and replace it with "_". So I need to find the space in the text that the player types and then replace it with someting else I hope you understand what I mean and that it is possible to do


Re: Detect something from a string and replace it with something else?? - NewTorran - 20.06.2010

Quote:
Originally Posted by Fj0rtizFredde
Hello
I could really use some help here but Im not the best at explaining things.
But lets say that I type in: "Hello world" in the chat then I want to find the " " (space) and replace it with "_". So I need to find the space in the text that the player types and then replace it with someting else I hope you understand what I mean and that it is possible to do
https://sampwiki.blast.hk/wiki/strfind

Hope that helps


Re: Detect something from a string and replace it with something else?? - Fj0rtizFredde - 20.06.2010

Not really since I still needs the text the player types but only without spaces :P So like I type "Hello world" the output will be "Hello_World" :P Hope you understand now :P


Re: Detect something from a string and replace it with something else?? - Jefff - 20.06.2010

Код:
stock SpaceChange(text[], ch = ' ')
{
	for(new i; text[i] != EOS; i++)
		if(text[i] == ch)
			text[i] = '_';
	return text;
}
new A[]="World is not enought";
printf("%s",SpaceChange(A));



Re: Detect something from a string and replace it with something else?? - RyDeR` - 20.06.2010

Try to find the position of the string you want to replace and just assign what it should be.

Like

pName[5] = '_';

Set's the 5'th character of the players name to _


Re: Detect something from a string and replace it with something else?? - Fj0rtizFredde - 20.06.2010

Quote:
Originally Posted by Jefff
Код:
stock SpaceChange(text[], ch = ' ')
{
	for(new i; text[i] != EOS; i++)
		if(text[i] == ch)
			text[i] = '_';
	return text;
}
new A[]="World is not enought";
printf("%s",SpaceChange(A));
Thanks Jefff It works perfect