Detect something from a string and replace it with something else??
#1

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
Reply
#2

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
Reply
#3

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
Reply
#4

Код:
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));
Reply
#5

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 _
Reply
#6

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)